Skip to content

Commit

Permalink
netbios_session: use SOCK_NONBLOCK flag
Browse files Browse the repository at this point in the history
Setting the NONBLOCK flag after the socket creation does not seem to
have any effect on Linux for connect().
  • Loading branch information
tguillem authored and jbkempf committed Jun 1, 2022
1 parent 919783d commit 6b6d715
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/netbios_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,27 @@

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

#ifndef _WIN32
#ifdef SOCK_NONBLOCK
/* Linux specific */
type |= SOCK_NONBLOCK;
#endif
if ((s->socket = socket(pf, type, 0)) < 0)
goto error;

#ifndef SOCK_NONBLOCK
/* Posix */
fcntl(s->socket, F_SETFL, fcntl(s->socket, F_GETFL, 0) | O_NONBLOCK);
#endif

#else
/* Windows */
if ((s->socket = socket(pf, type, 0)) < 0)
goto error;

ioctlsocket(s->socket, FIONBIO, &(unsigned long){ 1 });
#endif

Expand Down

0 comments on commit 6b6d715

Please sign in to comment.