static void write_cb(uv_write_t *req, int status) { lcb_luv_socket_t sock = (lcb_luv_socket_t)req->data; struct lcb_luv_evstate_st *evstate; if (!sock) { fprintf(stderr, "Got write callback (req=%p) without socket\n", (void *)req); return; } evstate = EVSTATE_FIND(sock, WRITE); if (status) { evstate->err = lcb_luv_errno_map((uv_last_error(sock->parent->loop)).code); } log_write_debug("Flush done. Flushed %d bytes", sock->write.buf.len); sock->write.pos = 0; sock->write.nb = 0; evstate->flags |= LCB_LUV_EVf_PENDING; evstate->flags &= ~(LCB_LUV_EVf_FLUSHING); if (SOCK_EV_ENABLED(sock, WRITE)) { sock->event->lcb_cb(sock->idx, LCB_WRITE_EVENT, sock->event->lcb_arg); if (sock->write.nb) { evstate->flags &= ~(LCB_LUV_EVf_PENDING); lcb_luv_flush(sock); } } lcb_luv_socket_unref(sock); }
static void async_cb(uv_async_t *handle, int status) { lcb_luv_socket_t sock = (lcb_luv_socket_t)handle->data; log_loop_trace("prepcb start"); if (!sock) { fprintf(stderr, "We were called with prepare_t %p, with a missing socket\n", (void *)handle); return; } sock->async_state |= LCB_LUV_ASYNCf_ENTERED; do { if (ASYNC_IS(sock, DEINIT)) { /** * We were requested to asynchronously be cancelled */ sock->async_state = 0; lcb_luv_socket_deinit(sock); break; } lcb_luv_socket_ref(sock); sock->async_state &= (~LCB_LUV_ASYNCf_REDO); maybe_callout(sock); lcb_luv_socket_unref(sock); } while (ASYNC_IS(sock, REDO)); sock->async_state &= ~( LCB_LUV_ASYNCf_ENTERED | LCB_LUV_ASYNCf_REDO | LCB_LUV_ASYNCf_SCHEDULED ); /** * we don't have an actual 'async_stop', so decrement the refcount * once more */ lcb_luv_socket_unref(sock); log_loop_trace("prepcb stop"); (void)status; }
void read_cb(uv_stream_t *stream, ssize_t nread, uv_buf_t buf) { /* This is the same buffer structure we had before */ lcb_luv_socket_t sock = (lcb_luv_socket_t)stream; int is_stopped = 0; (void)buf; lcb_luv_socket_ref(sock); log_read_debug("%d: nr=%d, len=%d", sock->idx, nread, buf.len); if (nread == -1) { uv_err_t last_err = uv_last_error(sock->parent->loop); if (last_err.code == UV_EOF) { sock->eof = 1; } else { sock->evstate[LCB_LUV_EV_READ].err = lcb_luv_errno_map(last_err.code); } lcb_luv_read_stop(sock); } else if (nread) { sock->read.buf.len -= nread; sock->read.buf.base += (size_t)nread; sock->read.nb += nread; /* We don't have any more space */ if (!sock->read.buf.len) { lcb_luv_read_stop(sock); } } else { /* nread == 0 */ goto GT_RET; } sock->evstate[LCB_LUV_EV_READ].flags |= LCB_LUV_EVf_PENDING; if (sock->event && (sock->event->lcb_events & LCB_READ_EVENT)) { sock->event->lcb_cb(sock->idx, LCB_READ_EVENT, sock->event->lcb_arg); } GT_RET: if (is_stopped) { lcb_luv_socket_unref(sock); } lcb_luv_socket_unref(sock); }
void lcb_luv_read_stop(lcb_luv_socket_t sock) { if (sock->read.readhead_active == 0) { return; } uv_read_stop((uv_stream_t*)&sock->tcp); sock->read.readhead_active = 0; lcb_luv_socket_unref(sock); }
void lcb_luv_schedule_disable(lcb_luv_socket_t sock) { if (sock->prep_active == 0) { log_loop_trace("prep_active is false"); return; } log_loop_debug("Disabling prepare"); uv_prepare_stop(&sock->prep); lcb_luv_socket_unref(sock); sock->prep_active = 0; }
static void async_cb(uv_async_t *handle, int status) { lcb_luv_socket_t sock = (lcb_luv_socket_t)handle->data; log_loop_trace("prepcb start"); if (!sock) { fprintf(stderr, "We were called with prepare_t %p, with a missing socket\n", (void*)handle); return; } sock->async_entered = 1; do { lcb_luv_socket_ref(sock); sock->async_redo = 0; maybe_callout(sock); lcb_luv_socket_unref(sock); } while (sock->async_redo); sock->async_entered = 0; sock->async_active = 0; /** * we don't have an actual 'async_stop', so decrement the refcount * once more */ lcb_luv_socket_unref(sock); log_loop_trace("prepcb stop"); (void)status; }
static void prepare_cb(uv_prepare_t *handle, int status) { lcb_luv_socket_t sock = (lcb_luv_socket_t)handle->data; log_loop_trace("prepcb start"); if (!sock) { fprintf(stderr, "We were called with prepare_t %p, with a missing socket\n", (void*)handle); return; } lcb_luv_socket_ref(sock); maybe_callout(sock); lcb_luv_socket_unref(sock); log_loop_trace("prepcb stop"); (void)status; }