From a84a77a4861c8fc1b0b6d3ec0931e83395cb34b5 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Sun, 29 Apr 2012 07:59:52 +0200 Subject: Fix TCP/IPC socket shutdown When socket in the process of asynchronous connect is being closed and the fact that there is no peer is found out at the same time close() may return ECONNRESET. This patch handles this situation decently. Signed-off-by: Martin Sustrik --- src/ipc_connecter.cpp | 9 ++++----- src/ipc_connecter.hpp | 2 +- src/tcp_connecter.cpp | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ipc_connecter.cpp b/src/ipc_connecter.cpp index ec9c5b1..af3665c 100644 --- a/src/ipc_connecter.cpp +++ b/src/ipc_connecter.cpp @@ -206,16 +206,15 @@ int xs::ipc_connecter_t::open () return -1; } -int xs::ipc_connecter_t::close () +void xs::ipc_connecter_t::close () { if (s == retired_fd) - return 0; + return; int rc = ::close (s); - if (rc != 0) - return -1; + errno_assert (rc == 0 || errno == ECONNRESET); + s = retired_fd; - return 0; } xs::fd_t xs::ipc_connecter_t::connect () diff --git a/src/ipc_connecter.hpp b/src/ipc_connecter.hpp index 2a874bc..e6c419d 100644 --- a/src/ipc_connecter.hpp +++ b/src/ipc_connecter.hpp @@ -81,7 +81,7 @@ namespace xs int open (); // Close the connecting socket. - int close (); + void close (); // Get the file descriptor of newly created connection. Returns // retired_fd if the connection was unsuccessfull. diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp index d1c04db..de105bb 100644 --- a/src/tcp_connecter.cpp +++ b/src/tcp_connecter.cpp @@ -307,7 +307,7 @@ void xs::tcp_connecter_t::close () wsa_assert (rc != SOCKET_ERROR); #else int rc = ::close (s); - errno_assert (rc == 0); + errno_assert (rc == 0 || errno == ECONNRESET); #endif s = retired_fd; } -- cgit v1.2.3