Skip to content

Commit 6b6d715

Browse files
tguillemjbkempf
authored andcommitted
netbios_session: use SOCK_NONBLOCK flag
Setting the NONBLOCK flag after the socket creation does not seem to have any effect on Linux for connect().
1 parent 919783d commit 6b6d715

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/netbios_session.c

+17-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,27 @@
5959

6060
static int open_socket_and_connect(netbios_session *s)
6161
{
62-
if ((s->socket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
63-
goto error;
62+
int pf = AF_INET;
63+
int type = SOCK_STREAM;
6464

6565
#ifndef _WIN32
66+
#ifdef SOCK_NONBLOCK
67+
/* Linux specific */
68+
type |= SOCK_NONBLOCK;
69+
#endif
70+
if ((s->socket = socket(pf, type, 0)) < 0)
71+
goto error;
72+
73+
#ifndef SOCK_NONBLOCK
74+
/* Posix */
6675
fcntl(s->socket, F_SETFL, fcntl(s->socket, F_GETFL, 0) | O_NONBLOCK);
76+
#endif
77+
6778
#else
79+
/* Windows */
80+
if ((s->socket = socket(pf, type, 0)) < 0)
81+
goto error;
82+
6883
ioctlsocket(s->socket, FIONBIO, &(unsigned long){ 1 });
6984
#endif
7085

0 commit comments

Comments
 (0)