/********** Server Side Code **********/ void sendResponse(noPollConn * conn, int requestLen) { int rc = nopoll_conn_send_binary(conn, serverResponseBuffer, requestLen); if (rc != requestLen) { LogPrintf("sendResponse failed %d", errno); // TODO: Handle EAGAIN to retry. So far this condition has not happened yet. } }
static int np_wt_write_request (void * args) { NpIOReq * req = (NpIOReq *)args; int rval; if(!nopoll_conn_is_ok(req->np_sock)) rval = -1; else { trace(LOG_PROTOCOL, "write request size:%d",req->bufsz); rval = nopoll_conn_send_binary(req->np_sock, req->bufp, req->bufsz); nopoll_conn_flush_writes (req->np_sock, 10, 0); /* assert(nopoll_conn_pending_write_bytes(req->np_sock) == 0);*/ } if (rval < 0) errno = ERR_OTHER; return rval; }
static void np_flush_with_flags(ChannelNP * c, int flags) { unsigned char * p = c->obuf->buf; assert(is_dispatch_thread()); assert(c->magic == CHANNEL_MAGIC); assert(c->chan.out.end == p + sizeof(c->obuf->buf)); assert(c->out_bin_block == NULL); assert(c->chan.out.cur >= p); assert(c->chan.out.cur <= p + sizeof(c->obuf->buf)); if (c->chan.out.cur == p) return; if (c->chan.state != ChannelStateDisconnected && c->out_errno == 0) { #if ENABLE_OutputQueue c->obuf->buf_len = c->chan.out.cur - p; c->out_queue.post_io_request = post_write_request; trace(LOG_PROTOCOL, "Outbuf add size:%d",c->obuf->buf_len); output_queue_add_obuf(&c->out_queue, c->obuf); c->obuf = output_queue_alloc_obuf(); c->chan.out.end = c->obuf->buf + sizeof(c->obuf->buf); #else while (p < c->chan.out.cur) { int rval = 0; size_t sz = c->chan.out.cur - p; if (!nopoll_conn_is_ok(c->np_socket)) rval = -1; if (rval >= 0) { rval = nopoll_conn_send_binary(c->np_socket, (const char *)p, sz); nopoll_conn_flush_writes (c->np_socket, 10, 0); /* assert(nopoll_conn_pending_write_bytes(c->np_socket) == 0);*/ } if (rval < 0) errno = ERR_OTHER; if (rval < 0) { int err = errno; trace(LOG_PROTOCOL, "Can't send() on channel %#lx: %s", c, errno_to_str(err)); c->out_errno = err; c->chan.out.cur = c->obuf->buf; c->out_eom_cnt = 0; return; } p += rval; } assert(p == c->chan.out.cur); #endif } c->chan.out.cur = c->obuf->buf; c->out_eom_cnt = 0; }