From 4016b657973bba87caf75168ba70aaa85d556487 Mon Sep 17 00:00:00 2001 From: Martin Lucina Date: Mon, 23 Jan 2012 09:00:28 +0100 Subject: Imported Upstream version 2.1.11 --- src/Makefile.in | 3 ++- src/clock.cpp | 12 ++++++++++++ src/device.cpp | 14 ++++++++++++++ src/err.cpp | 13 +++++++++++++ src/err.hpp | 26 ++++++++++++++------------ src/ip.cpp | 6 +++--- src/kqueue.cpp | 29 ++++++++++++++++++----------- src/mailbox.cpp | 5 +++++ src/platform.hpp.in | 12 ++++++++++++ src/tcp_socket.cpp | 26 +++++++++++++------------- src/uuid.cpp | 14 +++++++++++--- src/uuid.hpp | 5 +++++ src/xrep.cpp | 1 - src/zmq.cpp | 2 +- 14 files changed, 123 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/Makefile.in b/src/Makefile.in index f7a9436..8325786 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -208,6 +208,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LTVER = @LTVER@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ @@ -239,6 +240,7 @@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ @@ -274,7 +276,6 @@ libzmq_have_asciidoc = @libzmq_have_asciidoc@ libzmq_have_xmlto = @libzmq_have_xmlto@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ diff --git a/src/clock.cpp b/src/clock.cpp index f98a2f4..f1da091 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -34,6 +34,10 @@ #include #endif +#if defined HAVE_CLOCK_GETTIME +#include +#endif + zmq::clock_t::clock_t () : last_tsc (rdtsc ()), last_time (now_us () / 1000) @@ -61,6 +65,14 @@ uint64_t zmq::clock_t::now_us () double ticks_div = (double) (ticksPerSecond.QuadPart / 1000000); return (uint64_t) (tick.QuadPart / ticks_div); +#elif defined HAVE_CLOCK_GETTIME + + // Use POSIX clock_gettime function to get precise monotonic time. + struct timespec tv; + int rc = clock_gettime (CLOCK_MONOTONIC, &tv); + errno_assert (rc == 0); + return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_nsec / 1000); + #else // Use POSIX gettimeofday function to get precise time. diff --git a/src/device.cpp b/src/device.cpp index 351283a..4d86e91 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -20,6 +20,20 @@ #include +#include "platform.hpp" + +// On AIX, poll.h has to be included before zmq.h to get consistent +// definition of pollfd structure (AIX uses 'reqevents' and 'retnevents' +// instead of 'events' and 'revents' and defines macros to map from POSIX-y +// names to AIX-specific names). +#if defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_FREEBSD ||\ + defined ZMQ_HAVE_OPENBSD || defined ZMQ_HAVE_SOLARIS ||\ + defined ZMQ_HAVE_OSX || defined ZMQ_HAVE_QNXNTO ||\ + defined ZMQ_HAVE_HPUX || defined ZMQ_HAVE_AIX ||\ + defined ZMQ_HAVE_NETBSD +#include +#endif + #include "../include/zmq.h" #include "device.hpp" diff --git a/src/err.cpp b/src/err.cpp index d280487..ddc08ee 100644 --- a/src/err.cpp +++ b/src/err.cpp @@ -64,6 +64,19 @@ const char *zmq::errno_to_string (int errno_) } } +void zmq::zmq_abort(const char *errmsg_) +{ +#if defined ZMQ_HAVE_WINDOWS + + // Raise STATUS_FATAL_APP_EXIT. + ULONG_PTR extra_info [1]; + extra_info [0] = (ULONG_PTR) errmsg_; + RaiseException (0x40000015, EXCEPTION_NONCONTINUABLE, 1, extra_info); +#else + abort (); +#endif +} + #ifdef ZMQ_HAVE_WINDOWS const char *zmq::wsa_error() diff --git a/src/err.hpp b/src/err.hpp index 9558a10..7c7a9d8 100644 --- a/src/err.hpp +++ b/src/err.hpp @@ -42,6 +42,7 @@ namespace zmq { const char *errno_to_string (int errno_); + void zmq_abort (const char *errmsg_); } #ifdef ZMQ_HAVE_WINDOWS @@ -51,7 +52,7 @@ namespace zmq const char *wsa_error (); const char *wsa_error_no (int no_); void win_error (char *buffer_, size_t buffer_size_); - void wsa_error_to_errno (); + void wsa_error_to_errno (); } // Provides convenient way to check WSA-style errors on Windows. @@ -62,7 +63,7 @@ namespace zmq if (errstr != NULL) {\ fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \ __FILE__, __LINE__);\ - abort ();\ + zmq::zmq_abort (errstr);\ }\ }\ } while (false) @@ -74,7 +75,7 @@ namespace zmq if (errstr != NULL) {\ fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \ __FILE__, __LINE__);\ - abort ();\ + zmq::zmq_abort (errstr);\ }\ } while (false) @@ -86,7 +87,7 @@ namespace zmq zmq::win_error (errstr, 256);\ fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \ __FILE__, __LINE__);\ - abort ();\ + zmq::zmq_abort (errstr);\ }\ } while (false) @@ -100,7 +101,7 @@ namespace zmq if (unlikely (!(x))) {\ fprintf (stderr, "Assertion failed: %s (%s:%d)\n", #x, \ __FILE__, __LINE__);\ - abort ();\ + zmq::zmq_abort (#x);\ }\ } while (false) @@ -108,9 +109,9 @@ namespace zmq #define errno_assert(x) \ do {\ if (unlikely (!(x))) {\ - perror (NULL);\ - fprintf (stderr, "%s (%s:%d)\n", #x, __FILE__, __LINE__);\ - abort ();\ + const char *errstr = strerror (errno);\ + fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\ + zmq::zmq_abort (errstr);\ }\ } while (false) @@ -118,8 +119,9 @@ namespace zmq #define posix_assert(x) \ do {\ if (unlikely (x)) {\ - fprintf (stderr, "%s (%s:%d)\n", strerror (x), __FILE__, __LINE__);\ - abort ();\ + const char *errstr = strerror (x);\ + fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\ + zmq::zmq_abort (errstr);\ }\ } while (false) @@ -129,7 +131,7 @@ namespace zmq if (unlikely (x)) {\ const char *errstr = gai_strerror (x);\ fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\ - abort ();\ + zmq::zmq_abort (errstr);\ }\ } while (false) @@ -139,7 +141,7 @@ namespace zmq if (unlikely (!x)) {\ fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s:%d)\n",\ __FILE__, __LINE__);\ - abort ();\ + zmq::zmq_abort ("FATAL ERROR: OUT OF MEMORY");\ }\ } while (false) diff --git a/src/ip.cpp b/src/ip.cpp index 206f0e9..7ef698b 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -102,7 +102,7 @@ static int resolve_nic_name (in_addr* addr_, char const *interface_) return 0; } -#elif defined ZMQ_HAVE_AIX || ZMQ_HAVE_HPUX || ZMQ_HAVE_ANDROID +#elif defined ZMQ_HAVE_AIX || defined ZMQ_HAVE_HPUX || defined ZMQ_HAVE_ANDROID #include #include @@ -188,7 +188,7 @@ int zmq::open_socket (int domain_, int type_, int protocol_) { // Setting this option result in sane behaviour when exec() functions // are used. Old sockets are closed and don't block TCP ports etc. -#if defined SOCK_CLOEXEC +#if defined HAVE_SOCK_CLOEXEC type_ |= SOCK_CLOEXEC; #endif @@ -199,7 +199,7 @@ int zmq::open_socket (int domain_, int type_, int protocol_) // If there's no SOCK_CLOEXEC, let's try the second best option. Note that // race condition can cause socket not to be closed (if fork happens // between socket creation and this point). -#if !defined SOCK_CLOEXEC && defined FD_CLOEXEC +#if !defined HAVE_SOCK_CLOEXEC && defined FD_CLOEXEC int rc = fcntl (s, F_SETFD, FD_CLOEXEC); errno_assert (rc != -1); #endif diff --git a/src/kqueue.cpp b/src/kqueue.cpp index f173f84..fe4b65d 100644 --- a/src/kqueue.cpp +++ b/src/kqueue.cpp @@ -35,6 +35,7 @@ #include "err.hpp" #include "config.hpp" #include "i_poll_events.hpp" +#include "likely.hpp" // NetBSD defines (struct kevent).udata as intptr_t, everyone else // as void *. @@ -73,9 +74,7 @@ void zmq::kqueue_t::kevent_delete (fd_t fd_, short filter_) EV_SET (&ev, fd_, filter_, EV_DELETE, 0, 0, 0); int rc = kevent (kqueue_fd, &ev, 1, NULL, 0, NULL); - - if (rc == -1 && errno != ENOENT) - errno_assert (false); + errno_assert (rc != -1); } zmq::kqueue_t::handle_t zmq::kqueue_t::add_fd (fd_t fd_, @@ -110,29 +109,37 @@ void zmq::kqueue_t::rm_fd (handle_t handle_) void zmq::kqueue_t::set_pollin (handle_t handle_) { poll_entry_t *pe = (poll_entry_t*) handle_; - pe->flag_pollin = true; - kevent_add (pe->fd, EVFILT_READ, pe); + if (likely (!pe->flag_pollin)) { + pe->flag_pollin = true; + kevent_add (pe->fd, EVFILT_READ, pe); + } } void zmq::kqueue_t::reset_pollin (handle_t handle_) { poll_entry_t *pe = (poll_entry_t*) handle_; - pe->flag_pollin = false; - kevent_delete (pe->fd, EVFILT_READ); + if (likely (pe->flag_pollin)) { + pe->flag_pollin = false; + kevent_delete (pe->fd, EVFILT_READ); + } } void zmq::kqueue_t::set_pollout (handle_t handle_) { poll_entry_t *pe = (poll_entry_t*) handle_; - pe->flag_pollout = true; - kevent_add (pe->fd, EVFILT_WRITE, pe); + if (likely (!pe->flag_pollout)) { + pe->flag_pollout = true; + kevent_add (pe->fd, EVFILT_WRITE, pe); + } } void zmq::kqueue_t::reset_pollout (handle_t handle_) { poll_entry_t *pe = (poll_entry_t*) handle_; - pe->flag_pollout = false; - kevent_delete (pe->fd, EVFILT_WRITE); + if (likely (pe->flag_pollout)) { + pe->flag_pollout = false; + kevent_delete (pe->fd, EVFILT_WRITE); + } } void zmq::kqueue_t::start () diff --git a/src/mailbox.cpp b/src/mailbox.cpp index a99a9ec..24fa739 100644 --- a/src/mailbox.cpp +++ b/src/mailbox.cpp @@ -35,6 +35,11 @@ zmq::mailbox_t::mailbox_t () zmq::mailbox_t::~mailbox_t () { // TODO: Retrieve and deallocate commands inside the cpipe. + + // Work around problem that other threads might still be in our + // send() method, by waiting on the mutex before disappearing. + sync.lock (); + sync.unlock (); } zmq::fd_t zmq::mailbox_t::get_fd () diff --git a/src/platform.hpp.in b/src/platform.hpp.in index c89739d..12a5ab4 100644 --- a/src/platform.hpp.in +++ b/src/platform.hpp.in @@ -6,6 +6,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_ARPA_INET_H +/* Define to 1 if you have the `clock_gettime' function. */ +#undef HAVE_CLOCK_GETTIME + /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H @@ -30,6 +33,9 @@ /* Define to 1 if you have the `crypto' library (-lcrypto). */ #undef HAVE_LIBCRYPTO +/* Define to 1 if you have the `dcekt' library (-ldcekt). */ +#undef HAVE_LIBDCEKT + /* Define to 1 if you have the `iphlpapi' library (-liphlpapi). */ #undef HAVE_LIBIPHLPAPI @@ -75,6 +81,9 @@ /* Define to 1 if you have the `socket' function. */ #undef HAVE_SOCKET +/* Whether SOCK_CLOEXEC is defined and functioning. */ +#undef HAVE_SOCK_CLOEXEC + /* Define to 1 if stdbool.h conforms to C99. */ #undef HAVE_STDBOOL_H @@ -105,6 +114,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H +/* Define to 1 if you have the header file. */ +#undef HAVE_TIME_H + /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H diff --git a/src/tcp_socket.cpp b/src/tcp_socket.cpp index 07159d8..775a7a6 100644 --- a/src/tcp_socket.cpp +++ b/src/tcp_socket.cpp @@ -79,7 +79,7 @@ int zmq::tcp_socket_t::write (const void *data, int size) // we'll get an error (this may happen during the speculative write). if (nbytes == SOCKET_ERROR && WSAGetLastError () == WSAEWOULDBLOCK) return 0; - + // Signalise peer failure. if (nbytes == -1 && ( WSAGetLastError () == WSAENETDOWN || @@ -119,7 +119,7 @@ int zmq::tcp_socket_t::read (void *data, int size) // Orderly shutdown by the other peer. if (nbytes == 0) - return -1; + return -1; return (size_t) nbytes; } @@ -200,9 +200,6 @@ int zmq::tcp_socket_t::write (const void *data, int size) if (nbytes == -1 && (errno == ECONNRESET || errno == EPIPE)) return -1; - if (nbytes == 1) - fprintf (stderr, "E: unhandled error on send: %d/%s\n", - errno, strerror (errno)); errno_assert (nbytes != -1); return (size_t) nbytes; } @@ -214,18 +211,21 @@ int zmq::tcp_socket_t::read (void *data, int size) // Several errors are OK. When speculative read is being done we may not // be able to read a single byte to the socket. Also, SIGSTOP issued // by a debugging tool can result in EINTR error. - if (nbytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK || - errno == EINTR)) + if (nbytes == -1 + && (errno == EAGAIN + || errno == EWOULDBLOCK + || errno == EINTR)) return 0; - // Signalise peer failure. - if (nbytes == -1 && (errno == ECONNRESET || errno == ECONNREFUSED || - errno == ETIMEDOUT || errno == EHOSTUNREACH)) + // Signal peer failure. + if (nbytes == -1 + && (errno == ECONNRESET + || errno == ECONNREFUSED + || errno == ETIMEDOUT + || errno == EHOSTUNREACH + || errno == ENOTCONN)) return -1; - if (nbytes == 1) - fprintf (stderr, "E: unhandled error on recv: %d/%s\n", - errno, strerror (errno)); errno_assert (nbytes != -1); // Orderly shutdown by the other peer. diff --git a/src/uuid.cpp b/src/uuid.cpp index d8cc2e8..35d854f 100644 --- a/src/uuid.cpp +++ b/src/uuid.cpp @@ -44,14 +44,22 @@ const char *zmq::uuid_t::to_string () return (char*) string_buf; } -#elif defined ZMQ_HAVE_FREEBSD || defined ZMQ_HAVE_NETBSD +#elif defined ZMQ_HAVE_FREEBSD || defined ZMQ_HAVE_NETBSD || (defined ZMQ_HAVE_HPUX && defined HAVE_LIBDCEKT) #include -#include +#ifdef ZMQ_HAVE_HPUX +# include +#else +# include +#endif zmq::uuid_t::uuid_t () { +#ifdef ZMQ_HAVE_HPUX + unsigned32 status; +#else uint32_t status; +#endif uuid_create (&uuid, &status); zmq_assert (status == uuid_s_ok); uuid_to_string (&uuid, &string_buf, &status); @@ -67,7 +75,7 @@ zmq::uuid_t::~uuid_t () const char *zmq::uuid_t::to_string () { - return string_buf; + return (char*) string_buf; } #elif defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_SOLARIS ||\ diff --git a/src/uuid.hpp b/src/uuid.hpp index 5eab6c8..525dbcb 100644 --- a/src/uuid.hpp +++ b/src/uuid.hpp @@ -26,6 +26,8 @@ #if defined ZMQ_HAVE_FREEBSD || defined ZMQ_HAVE_NETBSD #include +#elif defined ZMQ_HAVE_HPUX && defined HAVE_LIBDCEKT +#include #elif defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_SOLARIS ||\ defined ZMQ_HAVE_OSX || defined ZMQ_HAVE_CYGWIN #include @@ -86,6 +88,9 @@ namespace zmq #elif defined ZMQ_HAVE_FREEBSD || defined ZMQ_HAVE_NETBSD ::uuid_t uuid; char *string_buf; +#elif defined ZMQ_HAVE_HPUX && defined HAVE_LIBDCEKT + ::uuid_t uuid; + unsigned_char_t *string_buf; #elif defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_SOLARIS ||\ defined ZMQ_HAVE_OSX || defined ZMQ_HAVE_CYGWIN ||\ defined ZMQ_HAVE_OPENVMS diff --git a/src/xrep.cpp b/src/xrep.cpp index ac4150d..c60d6a6 100644 --- a/src/xrep.cpp +++ b/src/xrep.cpp @@ -218,7 +218,6 @@ int zmq::xrep_t::xsend (zmq_msg_t *msg_, int flags_) int rc = zmq_msg_close (msg_); zmq_assert (rc == 0); } - // Detach the message from the data buffer. int rc = zmq_msg_init (msg_); zmq_assert (rc == 0); diff --git a/src/zmq.cpp b/src/zmq.cpp index dce9630..d6363b9 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -661,7 +661,7 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) } #else int rc = select (maxfd + 1, &inset, &outset, &errset, ptimeout); - if (unlikely (rc == -1) { + if (unlikely (rc == -1)) { if (errno == EINTR || errno == EBADF) return -1; errno_assert (false); -- cgit v1.2.3