summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDhammika Pathirana <dhammika@gmail.com>2010-12-13 14:18:47 +0100
committerMartin Sustrik <sustrik@250bpm.com>2010-12-13 14:18:47 +0100
commit22b2b9a2b6e1dd18d58ef51f453d2b4777e71be4 (patch)
treec7ea452d11f5bc606e1d41e7444c186ca46c36f6 /src
parenta9d969a73e303db2f6ddf436740d0bbef7e63dba (diff)
fix overwriting errno on bind failure
Signed-off-by: Dhammika Pathirana <dhammika@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/tcp_listener.cpp7
-rw-r--r--src/tcp_listener.hpp3
2 files changed, 8 insertions, 2 deletions
diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp
index 6d41069..22e9d4d 100644
--- a/src/tcp_listener.cpp
+++ b/src/tcp_listener.cpp
@@ -30,6 +30,7 @@
#ifdef ZMQ_HAVE_WINDOWS
zmq::tcp_listener_t::tcp_listener_t () :
+ has_file (false),
s (retired_fd)
{
memset (&addr, 0, sizeof (addr));
@@ -151,6 +152,7 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
#endif
zmq::tcp_listener_t::tcp_listener_t () :
+ has_file (false),
s (retired_fd)
{
memset (&addr, 0, sizeof (addr));
@@ -236,11 +238,12 @@ int zmq::tcp_listener_t::set_address (const char *protocol_, const char *addr_,
errno_assert (rc != -1);
// Bind the socket to the file path.
- rc = bind (s, (struct sockaddr*) &addr, sizeof (sockaddr_un));
+ rc = bind (s, (struct sockaddr*) &addr, addr_len);
if (rc != 0) {
close ();
return -1;
}
+ has_file = true;
// Listen for incomming connections.
rc = listen (s, backlog_);
@@ -270,7 +273,7 @@ int zmq::tcp_listener_t::close ()
// If there's an underlying UNIX domain socket, get rid of the file it
// is associated with.
struct sockaddr_un *su = (struct sockaddr_un*) &addr;
- if (AF_UNIX == su->sun_family) {
+ if (AF_UNIX == su->sun_family && has_file) {
rc = ::unlink(su->sun_path);
if (rc != 0)
return -1;
diff --git a/src/tcp_listener.hpp b/src/tcp_listener.hpp
index 1490a56..0e21dba 100644
--- a/src/tcp_listener.hpp
+++ b/src/tcp_listener.hpp
@@ -57,6 +57,9 @@ namespace zmq
sockaddr_storage addr;
socklen_t addr_len;
+ // True, if the undelying file for UNIX domain socket exists.
+ bool has_file;
+
// Underlying socket.
fd_t s;