brufuse/src/message-io.cpp
/**
 * Called by libuv as soon as some bytes have been read.
 */
Called by libuv as soon as some bytes have been read.
Called by libuv as soon as some bytes have been read .
static void on_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
    auto ct = reinterpret_cast<MessageContainer *>(stream->data);
    auto req = ct->message;
    if (nread == 0) return;
    if (nread < 0) {
        if (nread != UV_EOF) {
            fprintf(stderr, "An error occurred while reading a message: %s\n", uv_strerror(nread));
        }
        uv_read_stop(stream);
        Brufuse::close_and_free(stream);
        delete[] buf->base;
        delete ct->message;
        delete ct;
        return;
    }
    auto cbuf = reinterpret_cast<unsigned char *>(buf->base);
    ssize_t i = 0;
    while (!req->is_size_read() && i < nread) req->add_next_size_byte(cbuf[i++]);
    if (!req->is_size_read()) return;
    req->set_data_size(req->get_data_size());
    auto is_full = req->fill(cbuf + i, nread - i);
    if (is_full) {
        uv_read_stop(stream);
        delete[] buf->base;
        ct->cb(stream, req);
        delete ct;
    }
}
static void on_read ( uv_stream_t * stream , ssize_t nread , const uv_buf_t * buf ) { auto ct = reinterpret_cast < MessageContainer * > ( stream -> data ) ; auto req = ct -> message ; if ( nread == 0 ) return ; if ( nread < 0 ) { if ( nread != UV_EOF ) { fprintf ( stderr , " \n " , uv_strerror ( nread ) ) ; } uv_read_stop ( stream ) ; Brufuse :: close_and_free ( stream ) ; delete [ ] buf -> base ; delete ct -> message ; delete ct ; return ; } auto cbuf = reinterpret_cast < unsigned char * > ( buf -> base ) ; ssize_t i = 0 ; while ( ! req -> is_size_read ( ) && i < nread ) req -> add_next_size_byte ( cbuf [ i ++ ] ) ; if ( ! req -> is_size_read ( ) ) return ; req -> set_data_size ( req -> get_data_size ( ) ) ; auto is_full = req -> fill ( cbuf + i , nread - i ) ; if ( is_full ) { uv_read_stop ( stream ) ; delete [ ] buf -> base ; ct -> cb ( stream , req ) ; delete ct ; } }
Called by libuv as soon as some bytes have been read.
Called by libuv as soon as some bytes have been read .