+
+static int is_inprogress(void)
+{
+#ifdef WIN32
+ if (WSAGetLastError() == WSAEWOULDBLOCK)
+ return 1;
+#else
+ if (errno == EINPROGRESS)
+ return 1;
+#endif
+ return 0;
+}
+
+static void enable_nonblock(int sock)
+{
+ int flags;
+#ifdef WIN32
+ flags = (flags & CS_FLAGS_BLOCKING) ? 0 : 1;
+ if (ioctlsocket(sock, FIONBIO, &flags) < 0)
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "ioctlsocket");
+#else
+ if ((flags = fcntl(sock, F_GETFL, 0)) < 0)
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl");
+ if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0)
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2");
+#endif
+}