1 /*-------------------------------------------------------------------------
4 * set a file descriptor as non-blocking
6 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
12 *-------------------------------------------------------------------------
21 pg_set_noblock(int sock
)
24 return (fcntl(sock
, F_SETFL
, O_NONBLOCK
) != -1);
26 long ioctlsocket_ret
= 1;
28 /* Returns non-0 on failure, while fcntl() returns -1 on failure */
29 return (ioctlsocket(sock
, FIONBIO
, &ioctlsocket_ret
) == 0);
35 pg_set_block(int sock
)
40 flags
= fcntl(sock
, F_GETFL
);
41 if (flags
< 0 || fcntl(sock
, F_SETFL
, (long) (flags
& ~O_NONBLOCK
)))
45 long ioctlsocket_ret
= 0;
47 /* Returns non-0 on failure, while fcntl() returns -1 on failure */
48 return (ioctlsocket(sock
, FIONBIO
, &ioctlsocket_ret
) == 0);