static void initial_connect_timeout_handler(libcouchbase_socket_t sock, short which, void *arg) { libcouchbase_t instance = arg; libcouchbase_error_handler(instance, LIBCOUCHBASE_CONNECT_ERROR, "Could not connect to server within allotted time"); if (instance->sock != INVALID_SOCKET) { /* Do we need to delete the event? */ instance->io->delete_event(instance->io, instance->sock, instance->event); instance->io->close(instance->io, instance->sock); instance->sock = INVALID_SOCKET; } instance->io->delete_timer(instance->io, instance->timeout.event); instance->timeout.next = 0; libcouchbase_maybe_breakout(instance); (void)sock; (void)which; /* Notice we do not re-set the vbucket_state_listener. This is by design, * as we are still in the same state, and are just reporting an error * back to the user */ }
static void breakout_vbucket_state_listener(libcouchbase_server_t *server) { if(server->instance->vbucket_state_listener_last) { server->instance->vbucket_state_listener = server->instance->vbucket_state_listener_last; server->instance->vbucket_state_listener_last = NULL; } libcouchbase_maybe_breakout(server->instance); }
static void breakout_vbucket_state_listener(libcouchbase_server_t *server) { if (server->instance->vbucket_state_listener_last) { server->instance->vbucket_state_listener = server->instance->vbucket_state_listener_last; server->instance->vbucket_state_listener_last = NULL; } server->instance->io->delete_timer(server->instance->io, server->instance->timeout.event); libcouchbase_maybe_breakout(server->instance); }
void libcouchbase_server_event_handler(libcouchbase_socket_t sock, short which, void *arg) { libcouchbase_server_t *c = arg; (void)sock; if (which & LIBCOUCHBASE_READ_EVENT) { if (do_read_data(c) != 0) { /* TODO stash error message somewhere * "Failed to read from connection to \"%s:%s\"", c->hostname, c->port */ libcouchbase_failout_server(c, LIBCOUCHBASE_NETWORK_ERROR); return; } } if (which & LIBCOUCHBASE_WRITE_EVENT) { if (c->connected) { hrtime_t now = gethrtime(); hrtime_t tmo = c->instance->timeout.usec; tmo *= 1000; if (c->next_timeout != 0 && (now > (tmo + c->next_timeout))) { libcouchbase_purge_single_server(c, &c->cmd_log, &c->output_cookies, tmo, now, LIBCOUCHBASE_ETIMEDOUT); } } if (do_send_data(c) != 0) { /* TODO stash error message somewhere * "Failed to send to the connection to \"%s:%s\"", c->hostname, c->port */ libcouchbase_failout_server(c, LIBCOUCHBASE_NETWORK_ERROR); return; } } if (c->output.nbytes == 0) { c->instance->io->update_event(c->instance->io, c->sock, c->event, LIBCOUCHBASE_READ_EVENT, c, libcouchbase_server_event_handler); } else { c->instance->io->update_event(c->instance->io, c->sock, c->event, LIBCOUCHBASE_RW_EVENT, c, libcouchbase_server_event_handler); } libcouchbase_maybe_breakout(c->instance); /* Make it known that this was a success. */ libcouchbase_error_handler(c->instance, LIBCOUCHBASE_SUCCESS, NULL); }
static void timer_callback(libcouchbase_socket_t sock, short which, void *arg) { libcouchbase_timer_t timer = arg; libcouchbase_t instance = timer->instance; timer->callback(timer, instance, timer->cookie); if (hashset_is_member(instance->timers, timer) && !timer->periodic) { instance->io->delete_timer(instance->io, timer->event); libcouchbase_timer_destroy(instance, timer); } libcouchbase_maybe_breakout(timer->instance); (void)sock; (void)which; }