memcached的头文件

memcached版本:1.4.15

1、memcached.c

<sys/stat.h>:提供struct stat,stat()函数用于获取文件的属性。
<sys/socket.h>:定义socklen_t、sockaddr struct、sockaddr_storage struct、sa_family_t等,以及setsockopt()、listen()等。
<sys/un.h>:定义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]; /* 路径名 */
};

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

<pwd.h>:password结构,定义passwd struct(包含pw_name、pw_uid、pw_dir等变量),getpwnam()、getpwuid()等函数。
<sys/mman.h>:内存管理,MAP_SHARED等,mmap()等。
<fcntl.h>:fcntl()和open()。int open(const char *pathname, int flags, mode_t mode);
<netinet/tcp.h>:定义TCP_NODELAY(Avoid coalescing(合并) of small segments.),for use as a socket option at the IPPROTO_TCP level
<arpa/inet.h>:htonl()、htons()等函数,inet_addr()、inet_pton()、inet_ntop()等函数。
<errno.h>
<stdlib.h>:EXIT_SUCCESS等for exit(),atoi()、calloc()、getenv()、malloc()、realloc()、srand()、rand()、random()、strtod()、strtoul()等。
<stdio.h>
<string.h>
<time.h>:struct tm、struct timespec等,clock_t clock(void)、char* ctime(const time_t *)、time_t time(time_t *)等。
<assert.h>
<limits.h>
<sysexits.h>:定义了系统退出码,如EX_OK等
<stddef.h>:ptrdiff_t、size_type、wchar_t等,NULL、offsetof(type, member-designator)等。

2、memcached.h

<sys/types.h>:定义clock_t、dev_t、id_t、mode_t、pthread_t、size_t、uid_t等。

<sys/socket.h>

<sys/time.h>:timaval struct, fd_set, select(), gettimeofday(), getitimer(), FD_CLR()等。

<netinet/in.h>:struct in_addr, stuct sockaddr_in, IPPROTO_IP, IPPROTI_TCP, INADDR_ANY等。

<event.h>:用于libevent。

<netdb.h>:gethostbyaddr(), gethostbyname()等。

<pthread.h>

<unistd.h>: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()等。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值