1 /*-------------------------------------------------------------------------
4 * set a file descriptor as blocking or non-blocking
6 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
12 *-------------------------------------------------------------------------
21 * Put socket into nonblock mode.
22 * Returns true on success, false on failure.
25 pg_set_noblock(pgsocket sock
)
30 flags
= fcntl(sock
, F_GETFL
);
33 if (fcntl(sock
, F_SETFL
, (flags
| O_NONBLOCK
)) == -1)
37 unsigned long ioctlsocket_ret
= 1;
39 /* Returns non-0 on failure, while fcntl() returns -1 on failure */
40 return (ioctlsocket(sock
, FIONBIO
, &ioctlsocket_ret
) == 0);
45 * Put socket into blocking mode.
46 * Returns true on success, false on failure.
49 pg_set_block(pgsocket sock
)
54 flags
= fcntl(sock
, F_GETFL
);
57 if (fcntl(sock
, F_SETFL
, (flags
& ~O_NONBLOCK
)) == -1)
61 unsigned long ioctlsocket_ret
= 0;
63 /* Returns non-0 on failure, while fcntl() returns -1 on failure */
64 return (ioctlsocket(sock
, FIONBIO
, &ioctlsocket_ret
) == 0);