| 79 | } |
| 80 | |
| 81 | static apr_status_t socache_mc_init(ap_socache_instance_t *ctx, |
| 82 | const char *namespace, |
| 83 | const struct ap_socache_hints *hints, |
| 84 | server_rec *s, apr_pool_t *p) |
| 85 | { |
| 86 | apr_status_t rv; |
| 87 | int thread_limit = 0; |
| 88 | apr_uint16_t nservers = 0; |
| 89 | char *cache_config; |
| 90 | char *split; |
| 91 | char *tok; |
| 92 | |
| 93 | socache_mc_svr_cfg *sconf = ap_get_module_config(s->module_config, |
| 94 | &socache_memcache_module); |
| 95 | |
| 96 | ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit); |
| 97 | |
| 98 | /* Find all the servers in the first run to get a total count */ |
| 99 | cache_config = apr_pstrdup(p, ctx->servers); |
| 100 | split = apr_strtok(cache_config, ",", &tok); |
| 101 | while (split) { |
| 102 | nservers++; |
| 103 | split = apr_strtok(NULL,",", &tok); |
| 104 | } |
| 105 | |
| 106 | rv = apr_memcache_create(p, nservers, 0, &ctx->mc); |
| 107 | if (rv != APR_SUCCESS) { |
| 108 | ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(00785) |
| 109 | "Failed to create Memcache Object of '%d' size.", |
| 110 | nservers); |
| 111 | return rv; |
| 112 | } |
| 113 | |
| 114 | /* Now add each server to the memcache */ |
| 115 | cache_config = apr_pstrdup(p, ctx->servers); |
| 116 | split = apr_strtok(cache_config, ",", &tok); |
| 117 | while (split) { |
| 118 | apr_memcache_server_t *st; |
| 119 | char *host_str; |
| 120 | char *scope_id; |
| 121 | apr_port_t port; |
| 122 | |
| 123 | rv = apr_parse_addr_port(&host_str, &scope_id, &port, split, p); |
| 124 | if (rv != APR_SUCCESS) { |
| 125 | ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(00786) |
| 126 | "Failed to Parse memcache Server: '%s'", split); |
| 127 | return rv; |
| 128 | } |
| 129 | |
| 130 | if (host_str == NULL) { |
| 131 | ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(00787) |
| 132 | "Failed to Parse Server, " |
| 133 | "no hostname specified: '%s'", split); |
| 134 | return APR_EINVAL; |
| 135 | } |
| 136 | |
| 137 | if (port == 0) { |
| 138 | port = MC_DEFAULT_SERVER_PORT; |
nothing calls this directly
no test coverage detected