diff --git a/src/unix/stream.c b/src/unix/stream.c index 4d846f6a..ae2e6a04 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -630,6 +630,7 @@ int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) { static void uv__drain(uv_stream_t* stream) { uv_shutdown_t* req; + int status; assert(ngx_queue_empty(&stream->write_queue)); uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT); @@ -642,21 +643,17 @@ static void uv__drain(uv_stream_t* stream) { req = stream->shutdown_req; stream->shutdown_req = NULL; + stream->flags &= ~UV_STREAM_SHUTTING; uv__req_unregister(stream->loop, req); - if (shutdown(uv__stream_fd(stream), SHUT_WR)) { - /* Error. Report it. User should call uv_close(). */ + status = shutdown(uv__stream_fd(stream), SHUT_WR); + if (status) uv__set_sys_error(stream->loop, errno); - if (req->cb) { - req->cb(req, -1); - } - } else { - uv__set_sys_error(stream->loop, 0); - ((uv_handle_t*) stream)->flags |= UV_STREAM_SHUT; - if (req->cb) { - req->cb(req, 0); - } - } + else + stream->flags |= UV_STREAM_SHUT; + + if (req->cb != NULL) + req->cb(req, status); } }