summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fd_signaler.cpp78
-rw-r--r--src/ip.cpp4
-rw-r--r--src/tcp_connecter.hpp9
3 files changed, 87 insertions, 4 deletions
diff --git a/src/fd_signaler.cpp b/src/fd_signaler.cpp
index f42b95f..9ab307e 100644
--- a/src/fd_signaler.cpp
+++ b/src/fd_signaler.cpp
@@ -211,6 +211,84 @@ zmq::fd_t zmq::fd_signaler_t::get_fd ()
return r;
}
+#elif defined ZMQ_HAVE_HPUX || defined ZMQ_HAVE_AIX
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+zmq::fd_signaler_t::fd_signaler_t ()
+{
+ int sv [2];
+ int rc = socketpair (AF_UNIX, SOCK_STREAM, 0, sv);
+ errno_assert (rc == 0);
+ w = sv [0];
+ r = sv [1];
+
+ // Set the reader to non-blocking mode.
+ int flags = fcntl (r, F_GETFL, 0);
+ if (flags == -1)
+ flags = 0;
+ rc = fcntl (r, F_SETFL, flags | O_NONBLOCK);
+ errno_assert (rc != -1);
+}
+
+zmq::fd_signaler_t::~fd_signaler_t ()
+{
+ close (w);
+ close (r);
+}
+
+void zmq::fd_signaler_t::signal (int signal_)
+{
+ zmq_assert (signal_ >= 0 && signal_ < 64);
+ unsigned char c = (unsigned char) signal_;
+ ssize_t nbytes = send (w, &c, 1, 0);
+ errno_assert (nbytes == 1);
+}
+
+uint64_t zmq::fd_signaler_t::poll ()
+{
+ // Set the reader to blocking mode.
+ int flags = fcntl (fd, F_GETFL, 0);
+ if (flags == -1)
+ flags = 0;
+ int rc = fcntl (fd, F_SETFL, flags & ~O_NONBLOCK);
+ errno_assert (rc != -1);
+
+ // Poll for events.
+ uint64_t signals = check ();
+
+ // Set the reader to non-blocking mode.
+ flags = fcntl (r, F_GETFL, 0);
+ if (flags == -1)
+ flags = 0;
+ rc = fcntl (r, F_SETFL, flags | O_NONBLOCK);
+ errno_assert (rc != -1);
+
+ return signals;
+}
+
+uint64_t zmq::fd_signaler_t::check ()
+{
+ unsigned char buffer [64];
+ ssize_t nbytes = recv (r, buffer, 64, 0);
+ if (nbytes == -1 && errno == EAGAIN)
+ return 0;
+ zmq_assert (nbytes != -1);
+
+ uint64_t signals = 0;
+ for (int pos = 0; pos != nbytes; pos ++) {
+ zmq_assert (buffer [pos] < 64);
+ signals |= (uint64_t (1) << (buffer [pos]));
+ }
+ return signals;
+}
+
+zmq::fd_t zmq::fd_signaler_t::get_fd ()
+{
+ return r;
+}
+
#else
#include <sys/types.h>
diff --git a/src/ip.cpp b/src/ip.cpp
index 5e01c46..595689f 100644
--- a/src/ip.cpp
+++ b/src/ip.cpp
@@ -96,8 +96,6 @@ static int resolve_nic_name (in_addr* addr_, char const *interface_)
#include <sys/ioctl.h>
#include <net/if.h>
-#include "formatting.hpp"
-
static int resolve_nic_name (in_addr* addr_, char const *interface_)
{
// Create a socket.
@@ -107,7 +105,7 @@ static int resolve_nic_name (in_addr* addr_, char const *interface_)
struct ifreq ifr;
// Copy interface name for ioctl get.
- zmq_strncpy (ifr.ifr_name, interface_, sizeof (ifr.ifr_name));
+ strncpy (ifr.ifr_name, interface_, sizeof (ifr.ifr_name));
// Fetch interface address.
int rc = ioctl (sd, SIOCGIFADDR, (caddr_t) &ifr, sizeof (struct ifreq));
diff --git a/src/tcp_connecter.hpp b/src/tcp_connecter.hpp
index eee13ef..f1a124f 100644
--- a/src/tcp_connecter.hpp
+++ b/src/tcp_connecter.hpp
@@ -20,8 +20,15 @@
#ifndef __ZMQ_TCP_CONNECTER_HPP_INCLUDED__
#define __ZMQ_TCP_CONNECTER_HPP_INCLUDED__
+#include "platform.hpp"
#include "fd.hpp"
-#include "ip.hpp"
+
+#ifdef ZMQ_HAVE_WINDOWS
+#include "windows.hpp"
+#else
+#include <sys/types.h>
+#include <sys/socket.h>
+#endif
namespace zmq
{