clconfig_provider * lcb_clconfig_create_http(lcb_confmon *parent) { lcb_error_t status; struct lcb_io_use_st use; http_provider *http = calloc(1, sizeof(*http)); if (!http) { return NULL; } status = lcb_connection_init(&http->connection, parent->settings->io, parent->settings); if (status != LCB_SUCCESS) { free(http); return NULL; } if (! (http->nodes = hostlist_create())) { lcb_connection_cleanup(&http->connection); free(http); return NULL; } http->base.type = LCB_CLCONFIG_HTTP; http->base.refresh = get_refresh; http->base.pause = pause_http; http->base.get_cached = http_get_cached; http->base.shutdown = shutdown_http; http->base.nodes_updated = refresh_nodes; http->base.enabled = 0; http->io_timer = lcb_timer_create_simple(parent->settings->io, http, parent->settings->config_node_timeout, timeout_handler); lcb_timer_disarm(http->io_timer); http->disconn_timer = lcb_timer_create_simple(parent->settings->io, http, parent->settings->bc_http_stream_time, delayed_disconn); lcb_timer_disarm(http->disconn_timer); lcb_connuse_easy(&use, http, io_read_handler, io_error_handler); lcb_connection_use(&http->connection, &use); lcb_string_init(&http->stream.chunk); lcb_string_init(&http->stream.header); lcb_string_init(&http->stream.input); return &http->base; }
clconfig_provider * lcb_clconfig_create_cccp(lcb_confmon *mon) { cccp_provider *cccp = calloc(1, sizeof(*cccp)); cccp->nodes = hostlist_create(); cccp->base.type = LCB_CLCONFIG_CCCP; cccp->base.refresh = cccp_get; cccp->base.get_cached = cccp_get_cached; cccp->base.pause = cccp_pause; cccp->base.shutdown = cccp_cleanup; cccp->base.nodes_updated = nodes_updated; cccp->base.parent = mon; cccp->base.enabled = 0; cccp->timer = lcb_timer_create_simple(mon->settings->io, cccp, mon->settings->config_timeout, socket_timeout); lcb_timer_disarm(cccp->timer); if (!cccp->nodes) { free(cccp); return NULL; } if (lcb_connection_init(&cccp->connection, cccp->base.parent->settings->io, cccp->base.parent->settings) != LCB_SUCCESS) { free(cccp); return NULL; } return &cccp->base; }
lcb_error_t lcb_server_initialize(lcb_server_t *server, int servernum) { /* Initialize all members */ lcb_error_t err; char *p; const char *n = vbucket_config_get_server(server->instance->vbucket_config, servernum); err = lcb_connection_init(&server->connection, server->instance->settings.io, &server->instance->settings); if (err != LCB_SUCCESS) { return err; } server->connection.data = server; server->index = servernum; server->authority = strdup(n); strcpy(server->curhost.host, n); p = strchr(server->curhost.host, ':'); *p = '\0'; strcpy(server->curhost.port, p + 1); n = vbucket_config_get_couch_api_base(server->instance->vbucket_config, servernum); server->couch_api_base = (n != NULL) ? strdup(n) : NULL; n = vbucket_config_get_rest_api_server(server->instance->vbucket_config, servernum); server->rest_api_server = strdup(n); server->io_timer = lcb_timer_create_simple(server->instance->settings.io, server, MCSERVER_TIMEOUT(server), tmo_thunk); lcb_timer_disarm(server->io_timer); return LCB_SUCCESS; }