memcached的头文件

memcached版本:1.4.15

1、memcached.c

:提供struct stat,stat()函数用于获取文件的属性。
:定义socklen_t、sockaddr struct、sockaddr_storage struct、sa_family_t等,以及setsockopt()、listen()等。
:定义sockaddr_un struct(store addresses for UNIX domain sockets)。

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]; /* 路径名 */
};


:定义
PRIO_PROCESS等、RLIM_INFINITY等,以及rlimit struct、rusage struct,用于setpriority()setrlimit()getrusage()等函数。
:定义iovec struct,for vector I/O operations,如ssize_t readv(int, const struct iovec *, int)。
分类和转换单个字符,如isalpha()、isdigit()、isspace()等,以及tolower()、toupper()。
接收可变参数,定义va_list、va_start、va_end等。

:password结构,定义passwd struct(包含pw_name、pw_uid、pw_dir等变量),getpwnam()、getpwuid()等函数。
:内存管理,MAP_SHARED等,mmap()等。
:fcntl()和open()。int open(const char *pathname, int flags, mode_t mode);
:定义TCP_NODELAY(Avoid coalescing(合并) of small segments.for use as a socket option at the IPPROTO_TCP level
:htonl()、htons()等函数,inet_addr()、inet_pton()、inet_ntop()等函数。

EXIT_SUCCESS等for exit(),atoi()、calloc()、getenv()、malloc()、realloc()、srand()、rand()、random()、strtod()、strtoul()等。


struct tm、struct timespec等,clock_t clock(void)、char* ctime(const time_t *)、time_t time(time_t *)等。


:定义了系统退出码,如EX_OK等
:ptrdiff_t、size_type、wchar_t等,NULL、offsetof(type, member-designator)等。

2、memcached.h

定义clock_t、dev_t、id_t、mode_t、pthread_t、size_t、uid_t等。

:timaval struct, fd_set, select(), gettimeofday(), getitimer(), FD_CLR()等。

:struct in_addr, stuct sockaddr_in, IPPROTO_IP, IPPROTI_TCP, INADDR_ANY等。

:用于libevent。

:gethostbyaddr(), gethostbyname()等。

:SEEK_SET, STDIN_TILENO,dup(), execl(), getopt(), getuid(), lseek(), setsid(), sleep(), read()等。

 

"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()等。

你可能感兴趣的:(memcached)