summaryrefslogtreecommitdiff
path: root/src/ipc_listener.cpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-07-28 16:32:08 +0200
committerMartin Sustrik <sustrik@250bpm.com>2011-07-28 16:32:08 +0200
commitf63db009a1e1baf9f1fe7dae39901c7449c66131 (patch)
treeed18740f05af255b9179c4ebc045f4a1e95d47ca /src/ipc_listener.cpp
parentb45fec337aff8e04bebaf6e898a499f05ee6b0d6 (diff)
Different listener implementations simplified
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/ipc_listener.cpp')
-rw-r--r--src/ipc_listener.cpp63
1 files changed, 9 insertions, 54 deletions
diff --git a/src/ipc_listener.cpp b/src/ipc_listener.cpp
index a61ceed..200a2bc 100644
--- a/src/ipc_listener.cpp
+++ b/src/ipc_listener.cpp
@@ -111,33 +111,17 @@ int zmq::ipc_listener_t::set_address (const char *addr_)
if (s == -1)
return -1;
- // Set the non-blocking flag.
- int flag = fcntl (s, F_GETFL, 0);
- if (flag == -1)
- flag = 0;
- rc = fcntl (s, F_SETFL, flag | O_NONBLOCK);
- errno_assert (rc != -1);
-
// Bind the socket to the file path.
rc = bind (s, (struct sockaddr*) &addr, addr_len);
- if (rc != 0) {
- int err = errno;
- if (close () != 0)
- return -1;
- errno = err;
+ if (rc != 0)
return -1;
- }
+
has_file = true;
// Listen for incomming connections.
rc = listen (s, options.backlog);
- if (rc != 0) {
- int err = errno;
- if (close () != 0)
- return -1;
- errno = err;
+ if (rc != 0)
return -1;
- }
return 0;
}
@@ -164,44 +148,15 @@ int zmq::ipc_listener_t::close ()
zmq::fd_t zmq::ipc_listener_t::accept ()
{
+ // Accept one connection and deal with different failure modes.
zmq_assert (s != retired_fd);
-
- // Accept one incoming connection.
fd_t sock = ::accept (s, NULL, NULL);
-
-#if (defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_FREEBSD || \
- defined ZMQ_HAVE_OPENBSD || defined ZMQ_HAVE_OSX || \
- defined ZMQ_HAVE_OPENVMS || defined ZMQ_HAVE_NETBSD || \
- defined ZMQ_HAVE_CYGWIN)
- if (sock == -1 &&
- (errno == EAGAIN || errno == EWOULDBLOCK ||
- errno == EINTR || errno == ECONNABORTED))
- return retired_fd;
-#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_AIX)
- if (sock == -1 &&
- (errno == EWOULDBLOCK || errno == EINTR ||
- errno == ECONNABORTED || errno == EPROTO))
- return retired_fd;
-#elif defined ZMQ_HAVE_HPUX
- if (sock == -1 &&
- (errno == EAGAIN || errno == EWOULDBLOCK ||
- errno == EINTR || errno == ECONNABORTED || errno == ENOBUFS))
+ if (sock == -1) {
+ errno_assert (errno == EAGAIN || errno == EWOULDBLOCK ||
+ errno == EINTR || errno == ECONNABORTED || errno == EPROTO ||
+ errno == ENOBUFS);
return retired_fd;
-#elif defined ZMQ_HAVE_QNXNTO
- if (sock == -1 &&
- (errno == EWOULDBLOCK || errno == EINTR || errno == ECONNABORTED))
- return retired_fd;
-#endif
-
- errno_assert (sock != -1);
-
- // Set to non-blocking mode.
- int flags = fcntl (s, F_GETFL, 0);
- if (flags == -1)
- flags = 0;
- int rc = fcntl (sock, F_SETFL, flags | O_NONBLOCK);
- errno_assert (rc != -1);
-
+ }
return sock;
}