PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
noblock.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * noblock.c
4  * set a file descriptor as non-blocking
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * IDENTIFICATION
10  * src/port/noblock.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 
15 #include "c.h"
16 
17 #include <fcntl.h>
18 
19 
20 bool
22 {
23 #if !defined(WIN32)
24  return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
25 #else
26  unsigned long ioctlsocket_ret = 1;
27 
28  /* Returns non-0 on failure, while fcntl() returns -1 on failure */
29  return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
30 #endif
31 }
32 
33 
34 bool
36 {
37 #if !defined(WIN32)
38  int flags;
39 
40  flags = fcntl(sock, F_GETFL);
41  if (flags < 0 || fcntl(sock, F_SETFL, (long) (flags & ~O_NONBLOCK)))
42  return false;
43  return true;
44 #else
45  unsigned long ioctlsocket_ret = 0;
46 
47  /* Returns non-0 on failure, while fcntl() returns -1 on failure */
48  return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
49 #endif
50 }
bool pg_set_noblock(pgsocket sock)
Definition: noblock.c:21
bool pg_set_block(pgsocket sock)
Definition: noblock.c:35
int pgsocket
Definition: port.h:22