Merge branch 'master' of https://github.com/nanomsg/nanomsg

Conflicts:
	src/utils/int.h
diff --git a/AUTHORS b/AUTHORS
index b5f417c..104f055 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -24,6 +24,7 @@
 Manuel Mendez <mmendez534@gmail.com>
 Martin Sustrik <sustrik@250bpm.com>
 Matt Howlett <matt.howlett@gmail.com>
+Max Drechsler <max.drechsler@web.de>
 Mikko Koppanen <mikko@kuut.io>
 Nick Desaulniers <ndesaulniers@mozilla.com>
 Nicolas Hillegeer <nicolashillegeer@gmail.com>
@@ -37,5 +38,6 @@
 Sergey Kovalevich <inndie@gmail.com>
 Sergei Nikulov <sergey.nikulov@gmail.com>
 Steve McKay <shubalubdub@gmail.com>
+Tobias Peters <tobias.peters@kreativeffekt.at>
 Victor Guerra <vguerra@gmail.com>
 Zoltan Boszormenyi <zboszor@pr.hu>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6cdab79..31f358c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,7 +36,7 @@
     add_definitions (-D_CRT_SECURE_NO_WARNINGS)
 
     if (MINGW)
-        add_definitions (-DNN_HAVE_MINGW -D_WIN32_WINNT=0x0600)
+        add_definitions (-DNN_HAVE_MINGW -DNN_HAVE_STDINT -D_WIN32_WINNT=0x0600)
     endif ()
 else ()
     message (FATAL_ERROR "ERROR: CMake build system is intended only to generate MSVC solution files.\nUse autotools build system for any other purpose." )
diff --git a/configure.ac b/configure.ac
index 7240831..f44b3aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -226,6 +226,10 @@
         AC_DEFINE([NN_HAVE_SOLARIS])
         AC_CHECK_LIB([socket], [socket])
         AC_CHECK_LIB([nsl], [gethostbyname])
+    ],
+    [*nto-qnx*], [
+        AC_DEFINE([NN_HAVE_QNX])
+        AC_CHECK_LIB([socket], [socket])
     ]
 )
 
@@ -245,6 +249,7 @@
 AC_CHECK_HEADERS([unistd.h])
 AC_CHECK_HEADERS([sys/socket.h])
 AC_CHECK_HEADERS([sys/ioctl.h])
+AC_CHECK_HEADERS([stdint.h], [AC_DEFINE([NN_HAVE_STDINT])])
 
 AC_CHECK_FUNCS([eventfd], [AC_DEFINE([NN_HAVE_EVENTFD])])
 AC_CHECK_FUNCS([pipe], [AC_DEFINE([NN_HAVE_PIPE])])
diff --git a/doc/nn_ipc.txt b/doc/nn_ipc.txt
index d0c7392..bca181f 100644
--- a/doc/nn_ipc.txt
+++ b/doc/nn_ipc.txt
@@ -25,9 +25,7 @@
 files must be set in such a way that the appropriate applications can actually
 use them.
 
-On Windows, named pipes are used for IPC. IPC address is an arbitrary
-case-insensitive string containing any character except for backslash.
-Internally, address ipc://test means that named pipe \\.\pipe\test will be used.
+On Windows, IPC is not supported.
 
 EXAMPLE
 -------
diff --git a/src/core/global.c b/src/core/global.c
index b05f258..52a0931 100644
--- a/src/core/global.c
+++ b/src/core/global.c
@@ -514,6 +514,7 @@
     /*  Deallocate the socket object. */
     rc = nn_sock_term (self.socks [s]);
     if (nn_slow (rc == -EINTR)) {
+        nn_glock_unlock ();
         errno = EINTR;
         return -1;
     }
diff --git a/src/core/poll.c b/src/core/poll.c
index 904939f..cafd190 100644
--- a/src/core/poll.c
+++ b/src/core/poll.c
@@ -26,6 +26,7 @@
 
 #include "../utils/win.h"
 #include "../utils/fast.h"
+#include "../utils/sleep.h"
 #include "../utils/err.h"
 
 int nn_poll (struct nn_pollfd *fds, int nfds, int timeout)
@@ -66,12 +67,22 @@
     /*  Do the polling itself. */
     tv.tv_sec = timeout / 1000;
     tv.tv_usec = timeout % 1000 * 1000;
-    rc = select (-1, &fdset, NULL, NULL, &tv);
-    if (nn_slow (rc == 0))
+    if (nn_fast (nfds)) {
+        rc = select (-1, &fdset, NULL, NULL, &tv);
+        if (nn_slow (rc == 0))
+            return 0;
+        if (nn_slow (rc == SOCKET_ERROR)) {
+            errno = nn_err_wsa_to_posix (WSAGetLastError ());
+            return -1;
+        }
+    }
+    else {
+
+        //  POSIX platforms will sleep until timeout is expired,
+        //  so let's do the same on Windows.
+        if (timeout > 0)
+            nn_sleep(timeout);
         return 0;
-    if (nn_slow (rc == SOCKET_ERROR)) {
-        errno = nn_err_wsa_to_posix (WSAGetLastError ());
-        return -1;
     }
 
     /*  Move the results from fdset to the nanomsg pollset. */
diff --git a/src/utils/err.h b/src/utils/err.h
index 131d9e5..7dfcced 100644
--- a/src/utils/err.h
+++ b/src/utils/err.h
@@ -47,6 +47,7 @@
         if (nn_slow (!(x))) {\
             fprintf (stderr, "Assertion failed: %s (%s:%d)\n", #x, \
                 __FILE__, __LINE__);\
+            fflush (stderr);\
             nn_err_abort ();\
         }\
     } while (0)
@@ -58,6 +59,7 @@
                 "Assertion failed: %d == %s (%s:%d)\n", \
                 (obj)->state, #state_name, \
                 __FILE__, __LINE__);\
+            fflush (stderr);\
             nn_err_abort ();\
         }\
     } while (0)
@@ -68,6 +70,7 @@
         if (nn_slow (!x)) {\
             fprintf (stderr, "Out of memory (%s:%d)\n",\
                 __FILE__, __LINE__);\
+            fflush (stderr);\
             nn_err_abort ();\
         }\
     } while (0)
@@ -78,6 +81,7 @@
         if (nn_slow (!(x))) {\
             fprintf (stderr, "%s [%d] (%s:%d)\n", nn_err_strerror (errno),\
                 (int) errno, __FILE__, __LINE__);\
+            fflush (stderr);\
             nn_err_abort ();\
         }\
     } while (0)
@@ -88,6 +92,7 @@
         if (nn_slow (!(cond))) {\
             fprintf (stderr, "%s [%d] (%s:%d)\n", nn_err_strerror (err),\
                 (int) (err), __FILE__, __LINE__);\
+            fflush (stderr);\
             nn_err_abort ();\
         }\
     } while (0)
@@ -100,6 +105,7 @@
             nn_win_error ((int) GetLastError (), errstr, 256);\
             fprintf (stderr, "%s [%d] (%s:%d)\n",\
                 errstr, (int) GetLastError (), __FILE__, __LINE__);\
+            fflush (stderr);\
             nn_err_abort ();\
         }\
     } while (0)
@@ -112,6 +118,7 @@
             nn_win_error (WSAGetLastError (), errstr, 256);\
             fprintf (stderr, "%s [%d] (%s:%d)\n",\
                 errstr, (int) WSAGetLastError (), __FILE__, __LINE__);\
+            fflush (stderr);\
             nn_err_abort ();\
         }\
     } while (0)
@@ -121,6 +128,7 @@
     do {\
         fprintf (stderr, "%s: state=%d source=%d action=%d (%s:%d)\n", \
             message, state, src, type, __FILE__, __LINE__);\
+        fflush (stderr);\
         nn_err_abort ();\
     } while (0)
 
diff --git a/src/utils/int.h b/src/utils/int.h
index 4dce740..65e3c11 100644
--- a/src/utils/int.h
+++ b/src/utils/int.h
@@ -23,7 +23,7 @@
 #ifndef NN_INT_INCLUDED
 #define NN_INT_INCLUDED
 
-#if defined NN_HAVE_WINDOWS && !defined NN_HAVE_MINGW
+#if defined NN_HAVE_WINDOWS && !defined NN_HAVE_STDINT
 
 /*  Old versions of MSVC don't ship with stdint.h header file.
     Thus, we have to define fix-sized integer type ourselves. */