#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <ngx_md5.h>
#include "ngx_http_mxcache_module.h"
#include "ngx_connection_pool.h"
Go to the source code of this file.
Functions | |
static void * | ngx_http_mxcache_create_conf (ngx_conf_t *cf) |
Nginx module configuration. | |
static char * | ngx_http_mxcache_merge_conf (ngx_conf_t *cf, void *parent, void *child) |
Nginx module configuration. | |
ngx_http_mxcache_conn_t * | ngx_http_mxcache_create_new (ngx_http_request_t *r) |
Creates and initializes new mxcache structure. | |
ngx_int_t | ngx_http_mxcache_get (ngx_http_mxcache_conn_t *conn) |
Gets data from memcached - calls done_handler when data are ready. | |
ngx_int_t | ngx_http_mxcache_set (ngx_http_mxcache_conn_t *conn) |
Sets data to memcached - after all call done_handler. | |
ngx_int_t | ngx_http_mxcache_cleanup (ngx_http_mxcache_conn_t *conn) |
Cancels mxcache, free all mxcache resources. | |
static ngx_int_t | ngx_http_mxcache_init_conn (ngx_http_mxcache_conn_t *conn) |
Sets conn structure before connection. | |
static ngx_int_t | ngx_http_mxcache_create_get_request (ngx_http_mxcache_conn_t *conn) |
Creates request that will be sent to memcached. | |
static ngx_int_t | ngx_http_mxcache_create_set_request (ngx_http_mxcache_conn_t *conn) |
Creates request that will be sent to memcached. | |
static ngx_int_t | ngx_http_mxcache_flush_buffer (ngx_http_mxcache_conn_t *conn, ssize_t bytes) |
Moves data from conn->buffer to conn->out_bufs. | |
static void | ngx_http_mxcache_write_handler (ngx_event_t *wev) |
Handler called by nginx if socket is ready to write - write data to socket. | |
static void | ngx_http_mxcache_dummy_handler (ngx_event_t *ev) |
Handler that does nothing. | |
static void | ngx_http_mxcache_read_get_handler (ngx_event_t *rev) |
Handles data from memcached after get request. | |
static void | ngx_http_mxcache_read_set_handler (ngx_event_t *rev) |
Handles data from memcached after set request. | |
static ngx_int_t | ngx_http_mxcache_read_handler (ngx_event_t *rev) |
Handler called by nginx if socket is ready to read - read data from socket. | |
static void | ngx_http_mxcache_finalize_connection (ngx_http_mxcache_conn_t *conn, ngx_event_t *e, ngx_int_t rc) |
Closes connection and call done_handler if necessary. | |
static ngx_int_t | ngx_intmin (ngx_int_t a, ngx_int_t b) |
Helper function - minimum. | |
static ngx_int_t | ngx_intlen (ngx_int_t n) |
Helper function - count number digits. | |
ngx_int_t | ngx_http_mxcache_is_enabled (ngx_http_request_t *r) |
Checks if the module is enabled in config file. | |
Variables | |
static ngx_command_t | ngx_http_mxcache_commands [] |
Nginx module config file commands. | |
static ngx_http_module_t | ngx_http_mxcache_module_ctx |
Nginx module configuration. | |
ngx_module_t | ngx_http_mxcache_module |
Nginx module configuration. |
ngx_int_t ngx_http_mxcache_cleanup | ( | ngx_http_mxcache_conn_t * | conn | ) |
Cancels mxcache, free all mxcache resources.
conn | mxcache structure |
Definition at line 352 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::connection, ngx_http_mxcache_conn_s::done, ngx_http_mxcache_conn_s::done_handler, ngx_http_mxcache_conn_s::log, ngx_http_mxcache_conn_s::pool, and ngx_http_mxcache_conn_s::terminated.
Referenced by ngx_http_mxcache_finalize_connection(), ngx_http_xslt2_xml_cleanup(), ngx_http_xslt2_xml_mxcache_set_handler(), ngx_http_xslt2_xml_set_cached_stylesheet(), ngx_http_xxslt_parse_cleanup(), ngx_http_xxslt_parse_get_cached_include(), ngx_http_xxslt_parse_mxcache_set_handler(), and ngx_http_xxslt_parse_set_cached_include().
static void * ngx_http_mxcache_create_conf | ( | ngx_conf_t * | cf | ) | [static] |
Nginx module configuration.
cf | config |
Definition at line 1109 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conf_t::connection_pool, ngx_http_mxcache_conf_t::enabled, ngx_http_mxcache_conf_t::expire, ngx_http_mxcache_conf_t::log, NGX_HTTP_MXCACHE_BUFFER_SIZE, ngx_http_mxcache_conf_t::pool, ngx_http_mxcache_conf_t::server_ip, ngx_http_mxcache_conf_t::server_port, ngx_http_mxcache_conf_t::server_timeout, and ngx_http_mxcache_conf_t::sockaddr.
static ngx_int_t ngx_http_mxcache_create_get_request | ( | ngx_http_mxcache_conn_t * | conn | ) | [static] |
Creates request that will be sent to memcached.
conn | mxcache structure |
Definition at line 463 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::key, ngx_http_mxcache_conn_s::log, ngx_http_mxcache_conn_s::pool, and ngx_http_mxcache_conn_s::request.
Referenced by ngx_http_mxcache_get().
ngx_http_mxcache_conn_t * ngx_http_mxcache_create_new | ( | ngx_http_request_t * | r | ) |
Creates and initializes new mxcache structure.
r | nginx http request |
Definition at line 156 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::exp_time, ngx_http_mxcache_conf_t::expire, ngx_http_mxcache_conn_s::log, NGX_HTTP_MXCACHE_BUFFER_SIZE, ngx_http_mxcache_module, ngx_http_mxcache_conn_s::pool, ngx_http_mxcache_conn_s::r, ngx_http_mxcache_conn_s::read_timeout, ngx_http_mxcache_conn_s::rpool, ngx_http_mxcache_conf_t::server_timeout, and ngx_http_mxcache_conn_s::write_timeout.
Referenced by ngx_http_xslt2_xml_get_cached_stylesheet(), ngx_http_xslt2_xml_set_cached_stylesheet(), ngx_http_xxslt_parse_get_cached_include(), and ngx_http_xxslt_parse_set_cached_include().
static ngx_int_t ngx_http_mxcache_create_set_request | ( | ngx_http_mxcache_conn_t * | conn | ) | [static] |
Creates request that will be sent to memcached.
conn | mxcache structure |
Definition at line 505 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::bytes, ngx_http_mxcache_conn_s::exp_time, ngx_http_mxcache_conn_s::flag, ngx_http_mxcache_conn_s::key, ngx_http_mxcache_conn_s::log, ngx_intlen(), ngx_http_mxcache_conn_s::out_bufs, ngx_http_mxcache_conn_s::out_bufs_tail, ngx_http_mxcache_conn_s::pool, and ngx_http_mxcache_conn_s::request.
Referenced by ngx_http_mxcache_set().
static void ngx_http_mxcache_dummy_handler | ( | ngx_event_t * | ev | ) | [static] |
Handler that does nothing.
It's used by write_handler when all data was sent.
ev | nginx event |
Definition at line 704 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::data, and ngx_http_mxcache_conn_s::log.
Referenced by ngx_http_mxcache_write_handler().
static void ngx_http_mxcache_finalize_connection | ( | ngx_http_mxcache_conn_t * | conn, | |
ngx_event_t * | e, | |||
ngx_int_t | rc | |||
) | [static] |
Closes connection and call done_handler if necessary.
conn | mxcache structure | |
e | event cause finalize | |
rc | finalize status |
Definition at line 1062 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::connection, ngx_http_mxcache_conn_s::done, ngx_http_mxcache_conn_s::done_handler, ngx_http_mxcache_conn_s::error, ngx_http_mxcache_conn_s::log, ngx_connection_pool_release(), ngx_connection_pool_return(), ngx_http_mxcache_cleanup(), ngx_http_mxcache_conn_s::out_bufs_tail, and ngx_http_mxcache_conn_s::r.
Referenced by ngx_http_mxcache_read_get_handler(), ngx_http_mxcache_read_handler(), ngx_http_mxcache_read_set_handler(), and ngx_http_mxcache_write_handler().
static ngx_int_t ngx_http_mxcache_flush_buffer | ( | ngx_http_mxcache_conn_t * | conn, | |
ssize_t | bytes | |||
) | [static] |
Moves data from conn->buffer to conn->out_bufs.
conn | mxcache structure | |
bytes | number of bytes to process |
Definition at line 568 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::buffer, ngx_http_mxcache_conn_s::out_bufs, ngx_http_mxcache_conn_s::out_bufs_tail, ngx_http_mxcache_conn_s::r, and ngx_http_mxcache_conn_s::rpool.
Referenced by ngx_http_mxcache_read_get_handler(), and ngx_http_mxcache_read_handler().
ngx_int_t ngx_http_mxcache_get | ( | ngx_http_mxcache_conn_t * | conn | ) |
Gets data from memcached - calls done_handler when data are ready.
usage:
ngx_http_xcache_conn_t *conn;
conn = ngx_http_xcache_create_new(r);
conn->key = your_null_ended_u_char_key;
//void handler_called_after_all(ngx_http_xcache_conn_t *conn);
conn->done_handler = handler_called_after_all;
rc = ngx_http_xcache_get(conn); // send request, rc - ngx_int_t, error flag
void handler_called_after_all(ngx_http_xcache_conn_t *conn) { conn->error // error flag conn->out_bufs // value }
conn | mxcache structure |
Definition at line 226 of file ngx_http_mxcache_module.c.
References ngx_pooled_connection_s::connection, ngx_http_mxcache_conn_s::connection, ngx_http_mxcache_conf_t::enabled, ngx_http_mxcache_conn_s::log, ngx_http_mxcache_create_get_request(), ngx_http_mxcache_init_conn(), ngx_http_mxcache_module, ngx_http_mxcache_read_get_handler(), ngx_http_mxcache_write_handler(), ngx_http_mxcache_conn_s::out_bufs, ngx_http_mxcache_conn_s::out_bufs_tail, ngx_http_mxcache_conn_s::r, ngx_http_mxcache_conn_s::read_timeout, and ngx_http_mxcache_conn_s::write_timeout.
Referenced by ngx_http_xslt2_xml_get_cached_stylesheet(), and ngx_http_xxslt_parse_get_cached_include().
static ngx_int_t ngx_http_mxcache_init_conn | ( | ngx_http_mxcache_conn_t * | conn | ) | [static] |
Sets conn structure before connection.
Hashes conn->key using md5 function if key is longer than 100 characters. Gets connection from connection pool and assigns it to this request.
conn | mxcache structure |
Definition at line 385 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::buffer, ngx_pooled_connection_s::connection, ngx_http_mxcache_conn_s::connection, ngx_http_mxcache_conf_t::connection_pool, ngx_pooled_connection_s::data, ngx_http_mxcache_conn_s::done, ngx_http_mxcache_conn_s::error, ngx_http_mxcache_conn_s::key, ngx_http_mxcache_conn_s::log, ngx_connection_pool_get(), NGX_HTTP_MXCACHE_BUFFER_SIZE, ngx_http_mxcache_module, ngx_http_mxcache_conn_s::pool, ngx_http_mxcache_conn_s::r, ngx_http_mxcache_conn_s::read_timeout, ngx_http_mxcache_conn_s::response_length, ngx_http_mxcache_conn_s::rpool, ngx_http_mxcache_conn_s::state, ngx_http_mxcache_conn_s::terminated, and ngx_http_mxcache_conn_s::write_timeout.
Referenced by ngx_http_mxcache_get(), and ngx_http_mxcache_set().
ngx_int_t ngx_http_mxcache_is_enabled | ( | ngx_http_request_t * | r | ) |
Checks if the module is enabled in config file.
r | nginx http request |
Definition at line 142 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conf_t::enabled, and ngx_http_mxcache_module.
Referenced by ngx_http_xslt2_xml_get_cached_stylesheet(), ngx_http_xslt2_xml_set_cached_stylesheet(), ngx_http_xxslt_parse_get_cached_include(), and ngx_http_xxslt_parse_set_cached_include().
static char * ngx_http_mxcache_merge_conf | ( | ngx_conf_t * | cf, | |
void * | parent, | |||
void * | child | |||
) | [static] |
Nginx module configuration.
cf | config | |
parent | previous config | |
child | config |
Definition at line 1148 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conf_t::connection_pool, ngx_http_mxcache_conf_t::enabled, ngx_http_mxcache_conf_t::expire, ngx_connection_pool_create(), ngx_http_mxcache_conf_t::pool, ngx_http_mxcache_conf_t::server_ip, ngx_http_mxcache_conf_t::server_port, ngx_http_mxcache_conf_t::server_timeout, and ngx_http_mxcache_conf_t::sockaddr.
static void ngx_http_mxcache_read_get_handler | ( | ngx_event_t * | rev | ) | [static] |
Handles data from memcached after get request.
rev | nginx read event |
Definition at line 725 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::buffer, ngx_http_mxcache_conn_s::bytes, ngx_http_mxcache_conn_s::data, ngx_http_mxcache_conn_s::data_begin, ngx_http_mxcache_conn_s::flag, ngx_http_mxcache_conn_s::header_len, ngx_http_mxcache_conn_s::key, ngx_http_mxcache_conn_s::log, ngx_http_mxcache_finalize_connection(), ngx_http_mxcache_flush_buffer(), ngx_http_mxcache_read_handler(), ngx_http_mxcache_conn_s::out_bufs, ngx_http_mxcache_conn_s::out_bufs_tail, ngx_http_mxcache_conn_s::response_length, and ngx_http_mxcache_conn_s::state.
Referenced by ngx_http_mxcache_get().
static ngx_int_t ngx_http_mxcache_read_handler | ( | ngx_event_t * | rev | ) | [static] |
Handler called by nginx if socket is ready to read - read data from socket.
rev | nginx write event |
Definition at line 969 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::buffer, ngx_http_mxcache_conn_s::data, ngx_http_mxcache_conn_s::log, NGX_HTTP_MXCACHE_BUFFER_SIZE, ngx_http_mxcache_finalize_connection(), ngx_http_mxcache_flush_buffer(), ngx_http_mxcache_conn_s::r, ngx_http_mxcache_conn_s::read_timeout, ngx_http_mxcache_conn_s::response_length, ngx_http_mxcache_conn_s::rpool, and ngx_http_mxcache_conn_s::terminated.
Referenced by ngx_http_mxcache_read_get_handler(), and ngx_http_mxcache_read_set_handler().
static void ngx_http_mxcache_read_set_handler | ( | ngx_event_t * | rev | ) | [static] |
Handles data from memcached after set request.
rev | nginx read event |
Definition at line 918 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::buffer, ngx_http_mxcache_conn_s::data, ngx_http_mxcache_conn_s::log, ngx_http_mxcache_finalize_connection(), ngx_http_mxcache_read_handler(), ngx_intmin(), ngx_http_mxcache_conn_s::out_bufs, and ngx_http_mxcache_conn_s::response_length.
Referenced by ngx_http_mxcache_set().
ngx_int_t ngx_http_mxcache_set | ( | ngx_http_mxcache_conn_t * | conn | ) |
Sets data to memcached - after all call done_handler.
usage:
ngx_http_xcache_conn_t *conn;
conn = ngx_http_xcache_create_new(r); // r - ngx_http_request_t
conn->key = your_null_ended_u_char_key;
conn->exp_time = expire_time_in_seconds;
conn->out_bufs = value_in_chain_link_bufs;
conn->out_bufs_tail = last_chain_link;
conn->bytes = number_of_bytes_in_out_bufs;
//void handler_called_after_all(ngx_http_xcache_conn_t *conn);
conn->done_handler = handler_called_after_all;
rc = ngx_http_xcache_set(conn); // send request, rc - ngx_int_t, error flag
void handler_called_after_all(ngx_http_xcache_conn_t *conn) { conn->error // error flag }
conn | mxcache structure |
Definition at line 303 of file ngx_http_mxcache_module.c.
References ngx_pooled_connection_s::connection, ngx_http_mxcache_conn_s::connection, ngx_http_mxcache_conf_t::enabled, ngx_http_mxcache_conn_s::log, ngx_http_mxcache_create_set_request(), ngx_http_mxcache_init_conn(), ngx_http_mxcache_module, ngx_http_mxcache_read_set_handler(), ngx_http_mxcache_write_handler(), ngx_http_mxcache_conn_s::out_bufs, ngx_http_mxcache_conn_s::out_bufs_tail, ngx_http_mxcache_conn_s::r, ngx_http_mxcache_conn_s::read_timeout, and ngx_http_mxcache_conn_s::write_timeout.
Referenced by ngx_http_xslt2_xml_set_cached_stylesheet(), and ngx_http_xxslt_parse_set_cached_include().
static void ngx_http_mxcache_write_handler | ( | ngx_event_t * | wev | ) | [static] |
Handler called by nginx if socket is ready to write - write data to socket.
wev | nginx write event |
Definition at line 607 of file ngx_http_mxcache_module.c.
References ngx_http_mxcache_conn_s::data, ngx_http_mxcache_conn_s::log, ngx_http_mxcache_dummy_handler(), ngx_http_mxcache_finalize_connection(), ngx_http_mxcache_conn_s::r, ngx_http_mxcache_conn_s::request, ngx_http_mxcache_conn_s::terminated, and ngx_http_mxcache_conn_s::write_timeout.
Referenced by ngx_http_mxcache_get(), and ngx_http_mxcache_set().
static ngx_int_t ngx_intlen | ( | ngx_int_t | n | ) | [static] |
Helper function - count number digits.
n | number |
Definition at line 1211 of file ngx_http_mxcache_module.c.
Referenced by ngx_http_mxcache_create_set_request().
static ngx_int_t ngx_intmin | ( | ngx_int_t | a, | |
ngx_int_t | b | |||
) | [static] |
Helper function - minimum.
a | number | |
b | number |
Definition at line 1232 of file ngx_http_mxcache_module.c.
Referenced by ngx_http_mxcache_read_set_handler().
ngx_command_t ngx_http_mxcache_commands[] [static] |
Nginx module config file commands.
Definition at line 36 of file ngx_http_mxcache_module.c.
ngx_module_t ngx_http_mxcache_module |
{ NGX_MODULE_V1, &ngx_http_mxcache_module_ctx, ngx_http_mxcache_commands, NGX_HTTP_MODULE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NGX_MODULE_V1_PADDING }
Nginx module configuration.
Definition at line 84 of file ngx_http_mxcache_module.c.
Referenced by ngx_http_mxcache_create_new(), ngx_http_mxcache_get(), ngx_http_mxcache_init_conn(), ngx_http_mxcache_is_enabled(), and ngx_http_mxcache_set().
ngx_http_module_t ngx_http_mxcache_module_ctx [static] |
{ NULL,NULL,NULL,NULL,NULL,NULL, ngx_http_mxcache_create_conf, ngx_http_mxcache_merge_conf }
Nginx module configuration.
Definition at line 77 of file ngx_http_mxcache_module.c.