⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apr_memcache.c

📁 Apache官方在今天放出产品系列2.2的最新版本2.2.11的源码包 最流行的HTTP服务器软件之一
💻 C
📖 第 1 页 / 共 4 页
字号:
    rv = apr_pollset_create(&pollset, apr_hash_count(server_queries), temp_pool, 0);    if (rv != APR_SUCCESS) {        return rv;    }    /* send all the queries */    queries_sent = 0;    query_hash_index = apr_hash_first(temp_pool, server_queries);    while (query_hash_index) {        void *v;        apr_hash_this(query_hash_index, NULL, NULL, &v);        server_query = v;        query_hash_index = apr_hash_next(query_hash_index);        conn = server_query->conn;        ms = server_query->ms;        for (i = 0, rv = APR_SUCCESS; i < veclen && rv == APR_SUCCESS; i += APR_MAX_IOVEC_SIZE) {            rv = apr_socket_sendv(conn->sock, &(server_query->query_vec[i]),                                  veclen-i>APR_MAX_IOVEC_SIZE ? APR_MAX_IOVEC_SIZE : veclen-i , &written);        }        if (rv != APR_SUCCESS) {            mget_conn_result(FALSE, rv, mc, ms, conn,                             server_query, values, server_queries);            continue;        }        pollfds[queries_sent].desc_type = APR_POLL_SOCKET;        pollfds[queries_sent].reqevents = APR_POLLIN;        pollfds[queries_sent].p = temp_pool;        pollfds[queries_sent].desc.s = conn->sock;        pollfds[queries_sent].client_data = (void *)server_query;        apr_pollset_add (pollset, &pollfds[queries_sent]);        queries_sent++;    }    while (queries_sent) {        rv = apr_pollset_poll(pollset, MULT_GET_TIMEOUT, &queries_recvd, &activefds);        if (rv != APR_SUCCESS) {            /* timeout */            queries_sent = 0;            continue;        }        for (i = 0; i < queries_recvd; i++) {            server_query = activefds[i].client_data;            conn = server_query->conn;            ms = server_query->ms;           rv = get_server_line(conn);           if (rv != APR_SUCCESS) {               apr_pollset_remove (pollset, &activefds[i]);               mget_conn_result(FALSE, rv, mc, ms, conn,                                server_query, values, server_queries);               queries_sent--;               continue;           }           if (strncmp(MS_VALUE, conn->buffer, MS_VALUE_LEN) == 0) {               char *key;               char *flags;               char *length;               char *start;               char *last;               char *data;               apr_size_t len = 0;               start = conn->buffer;               key = apr_strtok(conn->buffer, " ", &last); /* just the VALUE, ignore */               key = apr_strtok(NULL, " ", &last);               flags = apr_strtok(NULL, " ", &last);               length = apr_strtok(NULL, " ", &last);               if (length) {                   len = atoi(length);               }               value = apr_hash_get(values, key, strlen(key));                              if (value) {                   if (len > 0)  {                       apr_bucket_brigade *bbb;                       apr_bucket *e;                                              /* eat the trailing \r\n */                       rv = apr_brigade_partition(conn->bb, len+2, &e);                                              if (rv != APR_SUCCESS) {                           apr_pollset_remove (pollset, &activefds[i]);                           mget_conn_result(FALSE, rv, mc, ms, conn,                                            server_query, values, server_queries);                           queries_sent--;                           continue;                       }                                              bbb = apr_brigade_split(conn->bb, e);                                              rv = apr_brigade_pflatten(conn->bb, &data, &len, data_pool);                                              if (rv != APR_SUCCESS) {                           apr_pollset_remove (pollset, &activefds[i]);                           mget_conn_result(FALSE, rv, mc, ms, conn,                                            server_query, values, server_queries);                           queries_sent--;                           continue;                       }                                              rv = apr_brigade_destroy(conn->bb);                       if (rv != APR_SUCCESS) {                           apr_pollset_remove (pollset, &activefds[i]);                           mget_conn_result(FALSE, rv, mc, ms, conn,                                            server_query, values, server_queries);                           queries_sent--;                           continue;                       }                                              conn->bb = bbb;                                              value->len = len - 2;                       data[value->len] = '\0';                       value->data = data;                   }                                      value->status = rv;                   value->flags = atoi(flags);                                      /* stay on the server */                   i--;                                  }               else {                   /* TODO: Server Sent back a key I didn't ask for or my                    *       hash is corrupt */               }           }           else if (strncmp(MS_END, conn->buffer, MS_END_LEN) == 0) {               /* this connection is done */               apr_pollset_remove (pollset, &activefds[i]);               ms_release_conn(ms, conn);               apr_hash_set(server_queries, &ms, sizeof(ms), NULL);                              queries_sent--;           }           else {               /* unknown reply? */               rv = APR_EGENERAL;           }                   } /* /for */    } /* /while */        query_hash_index = apr_hash_first(temp_pool, server_queries);    while (query_hash_index) {        void *v;        apr_hash_this(query_hash_index, NULL, NULL, &v);        server_query = v;        query_hash_index = apr_hash_next(query_hash_index);                conn = server_query->conn;        ms = server_query->ms;                mget_conn_result(TRUE, rv, mc, ms, conn,                         server_query, values, server_queries);        continue;    }        apr_pool_clear(temp_pool);    apr_pollset_destroy(pollset);    return APR_SUCCESS;    }/** * Define all of the strings for stats */#define STAT_pid MS_STAT " pid "#define STAT_pid_LEN (sizeof(STAT_pid)-1)#define STAT_uptime MS_STAT " uptime "#define STAT_uptime_LEN (sizeof(STAT_uptime)-1)#define STAT_time MS_STAT " time "#define STAT_time_LEN (sizeof(STAT_time)-1)#define STAT_version MS_STAT " version "#define STAT_version_LEN (sizeof(STAT_version)-1)#define STAT_pointer_size MS_STAT " pointer_size "#define STAT_pointer_size_LEN (sizeof(STAT_pointer_size)-1)#define STAT_rusage_user MS_STAT " rusage_user "#define STAT_rusage_user_LEN (sizeof(STAT_rusage_user)-1)#define STAT_rusage_system MS_STAT " rusage_system "#define STAT_rusage_system_LEN (sizeof(STAT_rusage_system)-1)#define STAT_curr_items MS_STAT " curr_items "#define STAT_curr_items_LEN (sizeof(STAT_curr_items)-1)#define STAT_total_items MS_STAT " total_items "#define STAT_total_items_LEN (sizeof(STAT_total_items)-1)#define STAT_bytes MS_STAT " bytes "#define STAT_bytes_LEN (sizeof(STAT_bytes)-1)#define STAT_curr_connections MS_STAT " curr_connections "#define STAT_curr_connections_LEN (sizeof(STAT_curr_connections)-1)#define STAT_total_connections MS_STAT " total_connections "#define STAT_total_connections_LEN (sizeof(STAT_total_connections)-1)#define STAT_connection_structures MS_STAT " connection_structures "#define STAT_connection_structures_LEN (sizeof(STAT_connection_structures)-1)#define STAT_cmd_get MS_STAT " cmd_get "#define STAT_cmd_get_LEN (sizeof(STAT_cmd_get)-1)#define STAT_cmd_set MS_STAT " cmd_set "#define STAT_cmd_set_LEN (sizeof(STAT_cmd_set)-1)#define STAT_get_hits MS_STAT " get_hits "#define STAT_get_hits_LEN (sizeof(STAT_get_hits)-1)#define STAT_get_misses MS_STAT " get_misses "#define STAT_get_misses_LEN (sizeof(STAT_get_misses)-1)#define STAT_evictions MS_STAT " evictions "#define STAT_evictions_LEN (sizeof(STAT_evictions)-1)#define STAT_bytes_read MS_STAT " bytes_read "#define STAT_bytes_read_LEN (sizeof(STAT_bytes_read)-1)#define STAT_bytes_written MS_STAT " bytes_written "#define STAT_bytes_written_LEN (sizeof(STAT_bytes_written)-1)#define STAT_limit_maxbytes MS_STAT " limit_maxbytes "#define STAT_limit_maxbytes_LEN (sizeof(STAT_limit_maxbytes)-1)#define STAT_threads MS_STAT " threads "#define STAT_threads_LEN (sizeof(STAT_threads)-1)static const char *stat_read_string(apr_pool_t *p, char *buf, apr_size_t len){    /* remove trailing \r\n and null char */    return apr_pstrmemdup(p, buf, len-2);}static apr_uint32_t stat_read_uint32(apr_pool_t *p, char *buf, apr_size_t  len){    buf[len-2] = '\0';    return atoi(buf);}static apr_uint64_t stat_read_uint64(apr_pool_t *p, char *buf, apr_size_t  len){    buf[len-2] = '\0';    return apr_atoi64(buf);}static apr_time_t stat_read_time(apr_pool_t *p, char *buf, apr_size_t  len){    buf[len-2] = '\0';    return apr_time_from_sec(atoi(buf));}static apr_time_t stat_read_rtime(apr_pool_t *p, char *buf, apr_size_t  len){    char *tok;    char *secs;    char *usecs;    const char *sep = ":.";    buf[len-2] = '\0';    secs = apr_strtok(buf, sep, &tok);    usecs = apr_strtok(NULL, sep, &tok);    if (secs && usecs) {        return apr_time_make(atoi(secs), atoi(usecs));    }    else {        return apr_time_make(0, 0);    }}/** * I got tired of Typing. Meh.  * * TODO: Convert it to static tables to make it cooler. */#define mc_stat_cmp(name) \    strncmp(STAT_ ## name, conn->buffer, STAT_ ## name ## _LEN) == 0#define mc_stat_str(name) \    stat_read_string(p, conn->buffer + name, \                     conn->blen - name)#define mc_stat_uint32(name) \    stat_read_uint32(p, conn->buffer + name, \                     conn->blen - name)#define mc_stat_uint64(name) \    stat_read_uint64(p, conn->buffer + name, \                     conn->blen - name)#define mc_stat_time(name) \    stat_read_time(p, conn->buffer + name, \                     conn->blen - name)#define mc_stat_rtime(name) \    stat_read_rtime(p, conn->buffer + name, \                     conn->blen - name)#define mc_do_stat(name, type) \    if (mc_stat_cmp(name)) { \        stats-> name = mc_stat_ ## type ((STAT_ ## name ## _LEN)); \    } static void update_stats(apr_pool_t *p, apr_memcache_conn_t *conn,                          apr_memcache_stats_t *stats){    mc_do_stat(version, str)    else mc_do_stat(pid, uint32)    else mc_do_stat(uptime, uint32)    else mc_do_stat(pointer_size, uint32)    else mc_do_stat(time, time)    else mc_do_stat(rusage_user, rtime)    else mc_do_stat(rusage_system, rtime)    else mc_do_stat(curr_items, uint32)    else mc_do_stat(total_items, uint32)    else mc_do_stat(bytes, uint64)    else mc_do_stat(curr_connections, uint32)    else mc_do_stat(total_connections, uint32)    else mc_do_stat(connection_structures, uint32)    else mc_do_stat(cmd_get, uint32)    else mc_do_stat(cmd_set, uint32)    else mc_do_stat(get_hits, uint32)    else mc_do_stat(get_misses, uint32)    else mc_do_stat(evictions, uint64)    else mc_do_stat(bytes_read, uint64)    else mc_do_stat(bytes_written, uint64)    else mc_do_stat(limit_maxbytes, uint32)    else mc_do_stat(threads, uint32)}APU_DECLARE(apr_status_t)apr_memcache_stats(apr_memcache_server_t *ms,                  apr_pool_t *p,                  apr_memcache_stats_t **stats) {    apr_memcache_stats_t *ret;    apr_status_t rv;    apr_memcache_conn_t *conn;    apr_size_t written;    struct iovec vec[2];    rv = ms_find_conn(ms, &conn);    if (rv != APR_SUCCESS) {        return rv;    }    /* version\r\n */    vec[0].iov_base = MC_STATS;    vec[0].iov_len  = MC_STATS_LEN;    vec[1].iov_base = MC_EOL;    vec[1].iov_len  = MC_EOL_LEN;    rv = apr_socket_sendv(conn->sock, vec, 2, &written);    if (rv != APR_SUCCESS) {        ms_bad_conn(ms, conn);        return rv;    }    ret = apr_pcalloc(p, sizeof(apr_memcache_stats_t));    do {        rv = get_server_line(conn);        if (rv != APR_SUCCESS) {            ms_bad_conn(ms, conn);            return rv;        }        if (strncmp(MS_END, conn->buffer, MS_END_LEN) == 0) {            rv = APR_SUCCESS;            break;        }        else if (strncmp(MS_STAT, conn->buffer, MS_STAT_LEN) == 0) {            update_stats(p, conn, ret);            continue;        }        else {            rv = APR_EGENERAL;            break;        }    } while(1);    ms_release_conn(ms, conn);    if (stats) {        *stats = ret;    }    return rv;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -