static UVC_ALLOC_CB(alloc_cb)
{
    UVC_ALLOC_CB_VARS()

    my_sockdata_t *sock = PTR_FROM_FIELD(my_sockdata_t, handle, tcp);
    buf->base = sock->iov.iov_base;
    buf->len = sock->iov.iov_len;

    (void)suggested_size;
    UVC_ALLOC_CB_RETURN();
}
Exemple #2
0
static UVC_ALLOC_CB(alloc_cb)
{
    UVC_ALLOC_CB_VARS()

    my_sockdata_t *sock = PTR_FROM_FIELD(my_sockdata_t, handle, tcp);
    struct lcb_buf_info *bi = &sock->base.read_buffer;
    buf->base = bi->iov[sock->cur_iov].iov_base;
    buf->len = (lcb_uvbuf_len_t)bi->iov[sock->cur_iov].iov_len;
    sock->cur_iov++;

    (void)suggested_size;
    UVC_ALLOC_CB_RETURN();
}
/**
 * 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);
}
Exemple #4
0
/******************************************************************************
 ******************************************************************************
 ** 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);
}
Exemple #5
0
/**
 * 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;

    lcb_assert(sock->refcount == 0);

    free_bufinfo_common(&sock->base.read_buffer);

    lcb_assert(sock->base.read_buffer.root == NULL);
    lcb_assert(sock->base.read_buffer.ringbuffer == NULL);

    memset(sock, 0xEE, sizeof(*sock));
    free(sock);

    decref_iops(&io->base);
}
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;
}
Exemple #7
0
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;
}