struct sockaddr {
unsigned short sa_family; /* address family, AF_xxx */
char sa_data[14]; /* 14 bytes of protocol address */
};
sockaddr_in(在netinet/in.h中定义):
struct sockaddr_in {
short int sin_family; /* Address family */
unsigned short int sin_port; /* Port number */
struct in_addr sin_addr; /* Internet address */
unsigned char sin_zero[8]; /* Same size as struct sockaddr */
};
struct in_addr {
unsigned long s_addr;
};
struct sockaddr_un
{
sa_family_t sun_family; /*PF_UNIX或AF_UNIX */
char sun_path[UNIX_PATH_MAX]; /* 路径名 */
};
"protocol_binary.h":用于实现二进制协议。
"cache.h":定义cache_t, cache_create(), cache_destroy(), cache_alloc(), cache_free()。
"sasl_defs.h":安全认证,可以打开或关闭此功能。
//以下几个头文件主要用于使用其中的函数,头文件中基本为函数声明。
"stats.h" "slabs.h" "assoc.h" "items.h" "trace.h" "hash.h" "util.h"
enum变量:
conn_states: Possible states of a connection, like conn_listening, conn_waiting, conn_read, ...
bin_substates: bin_reading_set_header, bin_read_set_value, bin_reading_get_key ...
protocol: ascii_prot, binary_prot, negotiating_prot.
network_transport: local_transport(Unix sockets), tcp_transport, udp_transport.
item_lock_types: ITEM_LOCK_GRANULAR, ITEM_LOCK_GLOBAL.
结构体变量(struct):
slab_stats: Stats stored per slab (and per thread). 包含set_cmds, get_hits, cas_hits等。
thread_stats: Stats stored per-thread. 包含get_misses, delete_misses, struct slab_stats slab_stats[ MAX_NUMBER_OF_SLAB_CLASSES]等。
stats: Global stats. 包含get_cmds, get_hits等。
settings: Globally accessible settings as derived from the commandline.
typedef struct _stritem{...} item: Structure for storing items within memcached.
typedef struct{...} LIBEVENT_THREAD:
typedef struct{...} LIBEVENT_DISPATCHER_THREAD: 包含struct event_base *base (libevent handle this thread uses).
typedef struct conn conn: representing a connection into memcached.
typedef struct conn conn;
struct conn {
int sfd;
sasl_conn_t *sasl_conn;
enum conn_states state;
enum bin_substates substate;
struct event event;
short ev_flags;
short which; /** which events were just triggered */
char *rbuf; /** buffer to read commands into */
char *rcurr; /** but if we parsed some already, this is where we stopped */
int rsize; /** total allocated size of rbuf */
int rbytes; /** how much data, starting from rcur, do we have unparsed */
char *wbuf;
char *wcurr;
int wsize;
int wbytes;
/** which state to go into after finishing current write */
enum conn_states write_and_go;
void *write_and_free; /** free this memory after finishing writing */
char *ritem; /** when we read in an item's value, it goes here */
int rlbytes;
/* data for the nread state */
/**
* item is used to hold an item structure created after reading the command
* line of set/add/replace commands, but before we finished reading the actual
* data. The data is read into ITEM_data(item) to avoid extra copying.
*/
void *item; /* for commands set/add/replace */
/* data for the swallow state */
int sbytes; /* how many bytes to swallow */
/* data for the mwrite state */
struct iovec *iov;
int iovsize; /* number of elements allocated in iov[] */
int iovused; /* number of elements used in iov[] */
struct msghdr *msglist;
int msgsize; /* number of elements allocated in msglist[] */
int msgused; /* number of elements used in msglist[] */
int msgcurr; /* element in msglist[] being transmitted now */
int msgbytes; /* number of bytes in current msg */
item **ilist; /* list of items to write out */
int isize;
item **icurr;
int ileft;
char **suffixlist;
int suffixsize;
char **suffixcurr;
int suffixleft;
enum protocol protocol; /* which protocol this connection speaks */
enum network_transport transport; /* what transport is used by this connection */
/* data for UDP clients */
int request_id; /* Incoming UDP request ID, if this is a UDP "connection" */
struct sockaddr request_addr; /* Who sent the most recent request */
socklen_t request_addr_size;
unsigned char *hdrbuf; /* udp packet headers */
int hdrsize; /* number of headers' worth of space is allocated */
bool noreply; /* True if the reply should not be sent. */
/* current stats command */
struct {
char *buffer;
size_t size;
size_t offset;
} stats;
/* Binary protocol stuff */
/* This is where the binary header goes */
protocol_binary_request_header binary_header;
uint64_t cas; /* the cas to return */
short cmd; /* current command being processed */
int opaque;
int keylen;
conn *next; /* Used for generating a list of conn structures */
LIBEVENT_THREAD *thread; /* Pointer to the thread object serving this connection */
};
函数声明:
声明于此,定于于memcached.c中的函数:
do_accept_new_conns(), do_add_delta(), do_store_item(), conn_new()等。
声明于此,定于于thread.c中的函数:
thread_init(), accept_new_conns(), item_touch(), item_lock(), STATS_LOCK()等。