From 536c5f8661af4b57f8cc8be43bf482ae27a9fcd8 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 8 Jun 2013 03:14:32 +0200 Subject: [PATCH] unix: clear UV_STREAM_SHUTTING after shutdown() Fix a state machine buglet where the UV_STREAM_SHUTTING flag didn't get cleared. --- src/unix/stream.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) 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); } }