mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
Move non-blocking code into its own /port file, for code clarity.
This commit is contained in:
35
src/port/noblock.c
Normal file
35
src/port/noblock.c
Normal file
@ -0,0 +1,35 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* noblock.c
|
||||
* set a file descriptor as non-blocking
|
||||
*
|
||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/port/noblock.c,v 1.1 2004/03/10 21:12:49 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
bool set_noblock(int sock)
|
||||
{
|
||||
#if !defined(WIN32) && !defined(__BEOS__)
|
||||
return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
|
||||
#else
|
||||
long ioctlsocket_ret = 1;
|
||||
|
||||
/* Returns non-0 on failure, while fcntl() returns -1 on failure */
|
||||
#ifdef WIN32
|
||||
return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
|
||||
#endif
|
||||
#ifdef __BEOS__
|
||||
return (ioctl(sock, FIONBIO, &ioctlsocket_ret) == 0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
Reference in New Issue
Block a user