#ifndef SOCK_CLOEXEC
# define SOCK_CLOEXEC 0
#endif
+#ifndef SOCK_NONBLOCK
+# define SOCK_NONBLOCk 0
+#endif
/* True if ERRNUM represents an error where the system call would
block if a blocking variant were used. */
s = socket_to_use;
if (s < 0)
{
- s = socket (family, p->socktype | SOCK_CLOEXEC, p->ai_protocol);
+ int socktype = p->socktype | SOCK_CLOEXEC;
+ if (p->is_non_blocking_client)
+ socktype |= SOCK_NONBLOCK;
+ s = socket (family, socktype, p->ai_protocol);
if (s < 0)
{
xerrno = errno;
}
}
-#ifdef DATAGRAM_SOCKETS
- if (!p->is_server && p->socktype == SOCK_DGRAM)
- break;
-#endif /* DATAGRAM_SOCKETS */
-
- if (p->is_non_blocking_client)
+ if (p->is_non_blocking_client && ! (SOCK_NONBLOCK && socket_to_use < 0))
{
ret = fcntl (s, F_SETFL, O_NONBLOCK);
if (ret < 0)
}
}
+#ifdef DATAGRAM_SOCKETS
+ if (!p->is_server && p->socktype == SOCK_DGRAM)
+ break;
+#endif /* DATAGRAM_SOCKETS */
+
/* Make us close S if quit. */
record_unwind_protect_int (close_file_unwind, s);