io/common.c
/**
 * Deliver an asynchronous 'write-ready' notification to libcouchbase.
 * This will invoke the normal callback chains..
 *
 * So how this works is rather complicated. It is used primarily for
 * write-readiness (i.e. to let libcouchbase put data into our socket buffer).
 *
 * If requested from within the callback (i.e. async_cb itself), then we need
 * to heuristically decide what exactly lcb will do.
 *
 * If it's a simple write event (i.e. actually copying the data between buffers)
 * then our buffer will eventually become full and this function will fail
 * to set the async_redo flag.
 *
 * The case is different in connect though: while a connect-readiness
 * notification is a write event, it doesn't actually fill the socket with
 * anything, so there is the possibility of recursion.
 *
 * Furthermore, connect-'readiness' is an actual event in uv, so there is no
 * need for this readiness emulation.
 */
Deliver an asynchronous 'write-ready' notification to libcouchbase.
This will invoke the normal callback chains

So how this works is rather complicated. It is used primarily for
write-readiness .

If requested from within the callback , then we need
to heuristically decide what exactly lcb will do.

If it's a simple write event
then our buffer will eventually become full and this function will fail
to set the async_redo flag.

The case is different in connect though: while a connect-readiness
notification is a write event, it doesn't actually fill the socket with
anything, so there is the possibility of recursion.

Furthermore, connect-'readiness' is an actual event in uv, so there is no
need for this readiness emulation.
Deliver an asynchronous ' write - ready ' notification to libcouchbase . This will invoke the normal callback chains So how this works is rather complicated . It is used primarily for write - readiness . If requested from within the callback then we need to heuristically decide what exactly lcb will do . If it ' s a simple write event then our buffer will eventually become full and this function will fail to set the async_redo flag . The case is different in connect though : while a connect - readiness notification is a write event it doesn ' t actually fill the socket with anything so there is the possibility of recursion . Furthermore connect - ' readiness ' is an actual event in uv so there is no need for this readiness emulation .
void
lcb_luv_send_async_write_ready(lcb_luv_socket_t sock)
{
    if (ASYNC_IS(sock, ENTERED)) {
        struct lcb_luv_evstate_st *wev = EVSTATE_FIND(sock, WRITE);
        struct lcb_luv_evstate_st *cev = EVSTATE_FIND(sock, CONNECT);
        if (!EVSTATE_IS(cev, CONNECTED)) {
            log_loop_debug("Not iterating again for phony write event");
            return;
        }
        if (EVSTATE_IS(wev, FLUSHING)) {
            log_loop_debug("Not requesting second iteration. "
                    "Already inside a flush");
            return;
        }
        if (sock->write.nb >= sizeof(sock->write.data)) {
            log_loop_debug("Not enough space to write..");
            return;
        }
        sock->async_state |= LCB_LUV_ASYNCf_REDO;
        return;
    }
    if (ASYNC_IS(sock, SCHEDULED)) {
        log_loop_trace("prep_active is true");
        return;
    }
    log_loop_debug("Will try and schedule prepare callback for %d", sock->idx);
    lcb_luv_socket_ref(sock);
    uv_async_send(&sock->async);
    sock->async_state |= LCB_LUV_ASYNCf_SCHEDULED;
}
void lcb_luv_send_async_write_ready ( lcb_luv_socket_t sock ) { if ( ASYNC_IS ( sock , ENTERED ) ) { struct lcb_luv_evstate_st * wev = EVSTATE_FIND ( sock , WRITE ) ; struct lcb_luv_evstate_st * cev = EVSTATE_FIND ( sock , CONNECT ) ; if ( ! EVSTATE_IS ( cev , CONNECTED ) ) { log_loop_debug ( " " ) ; return ; } if ( EVSTATE_IS ( wev , FLUSHING ) ) { log_loop_debug ( " " " " ) ; return ; } if ( sock -> write . nb >= sizeof ( sock -> write . data ) ) { log_loop_debug ( " " ) ; return ; } sock -> async_state |= LCB_LUV_ASYNCf_REDO ; return ; } if ( ASYNC_IS ( sock , SCHEDULED ) ) { log_loop_trace ( " " ) ; return ; } log_loop_debug ( " " , sock -> idx ) ; lcb_luv_socket_ref ( sock ) ; uv_async_send ( & sock -> async ) ; sock -> async_state |= LCB_LUV_ASYNCf_SCHEDULED ; }
Deliver an asynchronous 'write-ready' notification to libcouchbase.
Deliver an asynchronous ' write - ready ' notification to libcouchbase .
/**
         * Doing extra checks here to ensure we don't end up inside a busy
         * loop.
         */