/** * This one is called from uv_close */ static void socket_closed_callback(uv_handle_t *handle) { my_sockdata_t *sock = PTR_FROM_FIELD(my_sockdata_t, handle, tcp); my_iops_t *io = (my_iops_t *)sock->base.parent; if (sock->pending.read) { CbREQ(&sock->tcp)(&sock->base, -1, sock->rdarg); } memset(sock, 0xEE, sizeof(*sock)); free(sock); decref_iops(&io->base); }
/****************************************************************************** ****************************************************************************** ** Write Functions ** ****************************************************************************** ******************************************************************************/ static void write_callback(uv_write_t *req, int status) { my_write_t *mw = (my_write_t *)req; my_writebuf_t *wbuf = PTR_FROM_FIELD(my_writebuf_t, mw, write); my_sockdata_t *sock = wbuf->sock; lcb_io_write_cb callback = CbREQ(mw); if (callback) { callback(&sock->base, &wbuf->base, status); } SOCK_DECR_PENDING(sock, write); decref_sock(sock); }
static UVC_READ_CB(read_cb) { UVC_READ_CB_VARS() my_tcp_t *mt = (my_tcp_t *)stream; my_sockdata_t *sock = PTR_FROM_FIELD(my_sockdata_t, mt, tcp); my_iops_t *io = (my_iops_t *)sock->base.parent; lcb_ioC_read2_callback callback = CbREQ(mt); if (nread == 0) { /* we have a fixed IOV between requests, so just retry again */ return; } /** * XXX: * For multi-IOV support, we would require a counter to determine if this * EAGAIN is spurious (i.e. no previous data in buffer), or actual. In * the case of the former, we'd retry -- but in the latter it is a signal * that there is no more pending data within the socket buffer AND we have * outstanding data to deliver back to the caller. */ SOCK_DECR_PENDING(sock, read); uv_read_stop(stream); CbREQ(mt) = NULL; if (nread < 0) { set_last_error(io, uvc_last_errno(io->loop, nread)); if (uvc_is_eof(io->loop, nread)) { nread = 0; } } callback(&sock->base, nread, sock->rdarg); decref_sock(sock); (void)buf; }
static UVC_READ_CB(read_cb) { UVC_READ_CB_VARS() my_tcp_t *mt = (my_tcp_t *)stream; my_sockdata_t *sock = PTR_FROM_FIELD(my_sockdata_t, mt, tcp); lcb_io_read_cb callback = CbREQ(mt); /** * XXX: * For multi-IOV support, we would require a counter to determine if this * EAGAIN is spurious (i.e. no previous data in buffer), or actual. In * the case of the former, we'd retry -- but in the latter it is a signal * that there is no more pending data within the socket buffer AND we have * outstanding data to deliver back to the caller. */ if (nread == 0) { sock->cur_iov--; return; } SOCK_DECR_PENDING(sock, read); uv_read_stop(stream); CbREQ(mt) = NULL; if (callback) { callback(&sock->base, nread); #ifdef DEBUG } else { printf("No callback specified!!\n"); #endif } decref_sock(sock); (void)buf; }