PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
noblock.c File Reference
#include "c.h"
#include <fcntl.h>
Include dependency graph for noblock.c:

Go to the source code of this file.

Functions

bool pg_set_noblock (pgsocket sock)
 
bool pg_set_block (pgsocket sock)
 

Function Documentation

bool pg_set_block ( pgsocket  sock)

Definition at line 35 of file noblock.c.

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 at line 21 of file noblock.c.

Referenced by pgstat_init(), pq_init(), PQconnectPoll(), and report_fork_failure_to_client().

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 }