Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: queue write reqs if stream is not connected
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Jun 4, 2012
1 parent a30e45f commit cb9ca14
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/unix/stream.c
Expand Up @@ -890,42 +890,36 @@ int uv_write2(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt,
req->send_handle = send_handle;
ngx_queue_init(&req->queue);

if (bufcnt <= UV_REQ_BUFSML_SIZE) {
if (bufcnt <= UV_REQ_BUFSML_SIZE)
req->bufs = req->bufsml;
}
else {
else
req->bufs = malloc(sizeof(uv_buf_t) * bufcnt);
}

memcpy(req->bufs, bufs, bufcnt * sizeof(uv_buf_t));
req->bufcnt = bufcnt;

/*
* fprintf(stderr, "cnt: %d bufs: %p bufsml: %p\n", bufcnt, req->bufs, req->bufsml);
*/

req->write_index = 0;
stream->write_queue_size += uv__buf_count(bufs, bufcnt);

/* Append the request to write_queue. */
ngx_queue_insert_tail(&stream->write_queue, &req->queue);

assert(!ngx_queue_empty(&stream->write_queue));

/* If the queue was empty when this function began, we should attempt to
* do the write immediately. Otherwise start the write_watcher and wait
* for the fd to become writable.
*/
if (empty_queue) {
if (stream->connect_req) {
/* Still connecting, do nothing. */
}
else if (empty_queue) {
uv__write(stream);
} else {
}
else {
/*
* blocking streams should never have anything in the queue.
* if this assert fires then somehow the blocking stream isn't being
* sufficently flushed in uv__write.
* sufficiently flushed in uv__write.
*/
assert(!(stream->flags & UV_STREAM_BLOCKING));

uv__io_start(stream->loop, &stream->write_watcher);
}

Expand Down

0 comments on commit cb9ca14

Please sign in to comment.