src/http/modules/mxcache/ngx_http_mxcache_module.c File Reference

#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_tngx_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.

Function Documentation

ngx_int_t ngx_http_mxcache_cleanup ( ngx_http_mxcache_conn_t conn  ) 
static void * ngx_http_mxcache_create_conf ( ngx_conf_t *  cf  )  [static]
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.

Parameters:
conn mxcache structure
Returns:
NGX_OK or NGX_ERROR on error

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  ) 
static ngx_int_t ngx_http_mxcache_create_set_request ( ngx_http_mxcache_conn_t conn  )  [static]
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.

Parameters:
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]
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.

Parameters:
conn mxcache structure
bytes number of bytes to process
Returns:
NGX_OK or NGX_ERROR on error

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 }

Parameters:
conn mxcache structure
Returns:
NGX_*

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]
ngx_int_t ngx_http_mxcache_is_enabled ( ngx_http_request_t *  r  ) 
static char * ngx_http_mxcache_merge_conf ( ngx_conf_t *  cf,
void *  parent,
void *  child 
) [static]
static void ngx_http_mxcache_read_get_handler ( ngx_event_t *  rev  )  [static]
static ngx_int_t ngx_http_mxcache_read_handler ( ngx_event_t *  rev  )  [static]
static void ngx_http_mxcache_read_set_handler ( ngx_event_t *  rev  )  [static]
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 }

Parameters:
conn mxcache structure
Todo:
add configurable data size limit - for default mcached accept no more than 1MB.
Returns:
NGX_*

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]
static ngx_int_t ngx_intlen ( ngx_int_t  n  )  [static]

Helper function - count number digits.

Parameters:
n number
Returns:
number of digits

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.

Parameters:
a number
b number
Returns:
minimum of a and b

Definition at line 1232 of file ngx_http_mxcache_module.c.

Referenced by ngx_http_mxcache_read_set_handler().


Variable Documentation

ngx_command_t ngx_http_mxcache_commands[] [static]

Nginx module config file commands.

Definition at line 36 of file ngx_http_mxcache_module.c.

Initial value:
 {
        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]
Initial value:
 {
        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.


Generated on Mon Oct 12 14:03:36 2009 for XXSLT by  doxygen 1.6.1