Move non-blocking code into its own /port file, for code clarity.
This commit is contained in:
parent
ae22a6c185
commit
60a068b389
@ -1,5 +1,5 @@
|
||||
# -*-makefile-*-
|
||||
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.175 2004/02/10 03:42:42 tgl Exp $
|
||||
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.176 2004/03/10 21:12:46 momjian Exp $
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# All PostgreSQL makefiles include this file and use the variables it sets,
|
||||
@ -339,7 +339,7 @@ endif
|
||||
#
|
||||
# substitute implementations of the C library
|
||||
|
||||
LIBOBJS = @LIBOBJS@ path.o pgsleep.o sprompt.o thread.o
|
||||
LIBOBJS = @LIBOBJS@ noblock.o path.o pgsleep.o sprompt.o thread.o
|
||||
|
||||
ifneq (,$(LIBOBJS))
|
||||
LIBS += -lpgport
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.59 2004/03/09 05:11:52 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.60 2004/03/10 21:12:46 momjian Exp $
|
||||
* ----------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
@ -327,7 +327,7 @@ pgstat_init(void)
|
||||
* messages will be discarded; backends won't block waiting to send
|
||||
* messages to the collector.
|
||||
*/
|
||||
if (FCNTL_NONBLOCK(pgStatSock) < 0)
|
||||
if (!set_noblock(pgStatSock))
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
@ -1819,7 +1819,7 @@ pgstat_recvbuffer(void)
|
||||
* Set the write pipe to nonblock mode, so that we cannot block when
|
||||
* the collector falls behind.
|
||||
*/
|
||||
if (FCNTL_NONBLOCK(writePipe) < 0)
|
||||
if (!set_noblock(writePipe))
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
|
@ -37,7 +37,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.372 2004/03/09 05:11:52 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.373 2004/03/10 21:12:46 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@ -219,11 +219,6 @@ bool Db_user_namespace = false;
|
||||
|
||||
char *rendezvous_name;
|
||||
|
||||
/* For FNCTL_NONBLOCK */
|
||||
#if defined(WIN32) || defined(__BEOS__)
|
||||
long ioctlsocket_ret=1;
|
||||
#endif
|
||||
|
||||
/* list of library:init-function to be preloaded */
|
||||
char *preload_libraries_string = NULL;
|
||||
|
||||
@ -2365,7 +2360,7 @@ report_fork_failure_to_client(Port *port, int errnum)
|
||||
strerror(errnum));
|
||||
|
||||
/* Set port to non-blocking. Don't do send() if this fails */
|
||||
if (FCNTL_NONBLOCK(port->sock) < 0)
|
||||
if (!set_noblock(port->sock))
|
||||
return;
|
||||
|
||||
send(port->sock, buffer, strlen(buffer) + 1, 0);
|
||||
|
@ -12,7 +12,7 @@
|
||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/c.h,v 1.159 2004/01/10 23:39:51 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/include/c.h,v 1.160 2004/03/10 21:12:46 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -689,20 +689,6 @@ typedef NameData *Name;
|
||||
#define PG_BINARY_W "w"
|
||||
#endif
|
||||
|
||||
#if !defined(WIN32) && !defined(__BEOS__)
|
||||
#define FCNTL_NONBLOCK(sock) fcntl(sock, F_SETFL, O_NONBLOCK)
|
||||
#else
|
||||
extern long ioctlsocket_ret;
|
||||
|
||||
/* Returns non-0 on failure, while fcntl() returns -1 on failure */
|
||||
#ifdef WIN32
|
||||
#define FCNTL_NONBLOCK(sock) ((ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0) ? 0 : -1)
|
||||
#endif
|
||||
#ifdef __BEOS__
|
||||
#define FCNTL_NONBLOCK(sock) ((ioctl(sock, FIONBIO, &ioctlsocket_ret) == 0) ? 0 : -1)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(sun) && defined(__sparc__) && !defined(__SVR4)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/port.h,v 1.21 2004/03/09 04:49:02 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/port.h,v 1.22 2004/03/10 21:12:46 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -17,6 +17,9 @@
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
/* non-blocking */
|
||||
bool set_noblock(int sock);
|
||||
|
||||
/* Portable path handling for Unix/Win32 */
|
||||
extern bool is_absolute_path(const char *filename);
|
||||
extern char *first_path_separator(const char *filename);
|
||||
|
@ -4,7 +4,7 @@
|
||||
#
|
||||
# Copyright (c) 1994, Regents of the University of California
|
||||
#
|
||||
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.97 2004/02/02 00:11:31 momjian Exp $
|
||||
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.98 2004/03/10 21:12:46 momjian Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
@ -23,7 +23,7 @@ override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS) -DFRONTEND -DSYS
|
||||
OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
|
||||
fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
|
||||
dllist.o md5.o ip.o wchar.o encnames.o \
|
||||
$(filter crypt.o getaddrinfo.o inet_aton.o snprintf.o strerror.o path.o thread.o, $(LIBOBJS))
|
||||
$(filter crypt.o getaddrinfo.o inet_aton.o nonblock.o snprintf.o strerror.o path.o thread.o, $(LIBOBJS))
|
||||
ifeq ($(PORTNAME), win32)
|
||||
OBJS+=win32.o
|
||||
endif
|
||||
@ -52,7 +52,7 @@ backend_src = $(top_srcdir)/src/backend
|
||||
# For port modules, this only happens if configure decides the module
|
||||
# is needed (see filter hack in OBJS, above).
|
||||
|
||||
crypt.c getaddrinfo.c inet_aton.c snprintf.c strerror.c path.c thread.c: % : $(top_srcdir)/src/port/%
|
||||
crypt.c getaddrinfo.c inet_aton.c nonblock.c snprintf.c strerror.c path.c thread.c: % : $(top_srcdir)/src/port/%
|
||||
rm -f $@ && $(LN_S) $< .
|
||||
|
||||
md5.c ip.c: % : $(backend_src)/libpq/%
|
||||
@ -78,4 +78,4 @@ uninstall: uninstall-lib
|
||||
rm -f $(DESTDIR)$(includedir)/libpq-fe.h $(DESTDIR)$(includedir_internal)/libpq-int.h $(DESTDIR)$(includedir_internal)/pqexpbuffer.h
|
||||
|
||||
clean distclean maintainer-clean: clean-lib
|
||||
rm -f $(OBJS) crypt.c getaddrinfo.c inet_aton.c snprintf.c strerror.c path.c thread.c dllist.c md5.c ip.c encnames.c wchar.c
|
||||
rm -f $(OBJS) crypt.c getaddrinfo.c inet_aton.c nonblock.c snprintf.c strerror.c path.c thread.c dllist.c md5.c ip.c encnames.c wchar.c
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.267 2004/01/09 02:02:43 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.268 2004/03/10 21:12:47 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -50,11 +50,6 @@
|
||||
#include "libpq/ip.h"
|
||||
#include "mb/pg_wchar.h"
|
||||
|
||||
/* For FNCTL_NONBLOCK */
|
||||
#if defined(WIN32) || defined(__BEOS__)
|
||||
long ioctlsocket_ret=1;
|
||||
#endif
|
||||
|
||||
#define PGPASSFILE ".pgpass"
|
||||
|
||||
/* fall back options if they are not specified by arguments or defined
|
||||
@ -779,7 +774,7 @@ update_db_info(PGconn *conn)
|
||||
static int
|
||||
connectMakeNonblocking(PGconn *conn)
|
||||
{
|
||||
if (FCNTL_NONBLOCK(conn->sock) < 0)
|
||||
if (!set_noblock(conn->sock))
|
||||
{
|
||||
char sebuf[256];
|
||||
|
||||
|
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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user