Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 60a068b

Browse files
committed
Move non-blocking code into its own /port file, for code clarity.
1 parent ae22a6c commit 60a068b

File tree

8 files changed

+53
-39
lines changed

8 files changed

+53
-39
lines changed

src/Makefile.global.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*-makefile-*-
2-
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.175 2004/02/10 03:42:42 tgl Exp $
2+
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.176 2004/03/10 21:12:46 momjian Exp $
33

44
#------------------------------------------------------------------------------
55
# All PostgreSQL makefiles include this file and use the variables it sets,
@@ -339,7 +339,7 @@ endif
339339
#
340340
# substitute implementations of the C library
341341

342-
LIBOBJS = @LIBOBJS@ path.o pgsleep.o sprompt.o thread.o
342+
LIBOBJS = @LIBOBJS@ noblock.o path.o pgsleep.o sprompt.o thread.o
343343

344344
ifneq (,$(LIBOBJS))
345345
LIBS += -lpgport

src/backend/postmaster/pgstat.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
1515
*
16-
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.59 2004/03/09 05:11:52 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.60 2004/03/10 21:12:46 momjian Exp $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -327,7 +327,7 @@ pgstat_init(void)
327327
* messages will be discarded; backends won't block waiting to send
328328
* messages to the collector.
329329
*/
330-
if (FCNTL_NONBLOCK(pgStatSock) < 0)
330+
if (!set_noblock(pgStatSock))
331331
{
332332
ereport(LOG,
333333
(errcode_for_socket_access(),
@@ -1819,7 +1819,7 @@ pgstat_recvbuffer(void)
18191819
* Set the write pipe to nonblock mode, so that we cannot block when
18201820
* the collector falls behind.
18211821
*/
1822-
if (FCNTL_NONBLOCK(writePipe) < 0)
1822+
if (!set_noblock(writePipe))
18231823
{
18241824
ereport(LOG,
18251825
(errcode_for_socket_access(),

src/backend/postmaster/postmaster.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.372 2004/03/09 05:11:52 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.373 2004/03/10 21:12:46 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -219,11 +219,6 @@ bool Db_user_namespace = false;
219219

220220
char *rendezvous_name;
221221

222-
/* For FNCTL_NONBLOCK */
223-
#if defined(WIN32) || defined(__BEOS__)
224-
long ioctlsocket_ret=1;
225-
#endif
226-
227222
/* list of library:init-function to be preloaded */
228223
char *preload_libraries_string = NULL;
229224

@@ -2365,7 +2360,7 @@ report_fork_failure_to_client(Port *port, int errnum)
23652360
strerror(errnum));
23662361

23672362
/* Set port to non-blocking. Don't do send() if this fails */
2368-
if (FCNTL_NONBLOCK(port->sock) < 0)
2363+
if (!set_noblock(port->sock))
23692364
return;
23702365

23712366
send(port->sock, buffer, strlen(buffer) + 1, 0);

src/include/c.h

+1-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $PostgreSQL: pgsql/src/include/c.h,v 1.159 2004/01/10 23:39:51 neilc Exp $
15+
* $PostgreSQL: pgsql/src/include/c.h,v 1.160 2004/03/10 21:12:46 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -689,20 +689,6 @@ typedef NameData *Name;
689689
#define PG_BINARY_W "w"
690690
#endif
691691

692-
#if !defined(WIN32) && !defined(__BEOS__)
693-
#define FCNTL_NONBLOCK(sock) fcntl(sock, F_SETFL, O_NONBLOCK)
694-
#else
695-
extern long ioctlsocket_ret;
696-
697-
/* Returns non-0 on failure, while fcntl() returns -1 on failure */
698-
#ifdef WIN32
699-
#define FCNTL_NONBLOCK(sock) ((ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0) ? 0 : -1)
700-
#endif
701-
#ifdef __BEOS__
702-
#define FCNTL_NONBLOCK(sock) ((ioctl(sock, FIONBIO, &ioctlsocket_ret) == 0) ? 0 : -1)
703-
#endif
704-
#endif
705-
706692
#if defined(sun) && defined(__sparc__) && !defined(__SVR4)
707693
#include <unistd.h>
708694
#endif

src/include/port.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.21 2004/03/09 04:49:02 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.22 2004/03/10 21:12:46 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -17,6 +17,9 @@
1717
#include <netdb.h>
1818
#endif
1919

20+
/* non-blocking */
21+
bool set_noblock(int sock);
22+
2023
/* Portable path handling for Unix/Win32 */
2124
extern bool is_absolute_path(const char *filename);
2225
extern char *first_path_separator(const char *filename);

src/interfaces/libpq/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.97 2004/02/02 00:11:31 momjian Exp $
7+
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.98 2004/03/10 21:12:46 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -23,7 +23,7 @@ override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS) -DFRONTEND -DSYS
2323
OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
2424
fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
2525
dllist.o md5.o ip.o wchar.o encnames.o \
26-
$(filter crypt.o getaddrinfo.o inet_aton.o snprintf.o strerror.o path.o thread.o, $(LIBOBJS))
26+
$(filter crypt.o getaddrinfo.o inet_aton.o nonblock.o snprintf.o strerror.o path.o thread.o, $(LIBOBJS))
2727
ifeq ($(PORTNAME), win32)
2828
OBJS+=win32.o
2929
endif
@@ -52,7 +52,7 @@ backend_src = $(top_srcdir)/src/backend
5252
# For port modules, this only happens if configure decides the module
5353
# is needed (see filter hack in OBJS, above).
5454

55-
crypt.c getaddrinfo.c inet_aton.c snprintf.c strerror.c path.c thread.c: % : $(top_srcdir)/src/port/%
55+
crypt.c getaddrinfo.c inet_aton.c nonblock.c snprintf.c strerror.c path.c thread.c: % : $(top_srcdir)/src/port/%
5656
rm -f $@ && $(LN_S) $< .
5757

5858
md5.c ip.c: % : $(backend_src)/libpq/%
@@ -78,4 +78,4 @@ uninstall: uninstall-lib
7878
rm -f $(DESTDIR)$(includedir)/libpq-fe.h $(DESTDIR)$(includedir_internal)/libpq-int.h $(DESTDIR)$(includedir_internal)/pqexpbuffer.h
7979

8080
clean distclean maintainer-clean: clean-lib
81-
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
81+
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

src/interfaces/libpq/fe-connect.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.267 2004/01/09 02:02:43 momjian Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.268 2004/03/10 21:12:47 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -50,11 +50,6 @@
5050
#include "libpq/ip.h"
5151
#include "mb/pg_wchar.h"
5252

53-
/* For FNCTL_NONBLOCK */
54-
#if defined(WIN32) || defined(__BEOS__)
55-
long ioctlsocket_ret=1;
56-
#endif
57-
5853
#define PGPASSFILE ".pgpass"
5954

6055
/* fall back options if they are not specified by arguments or defined
@@ -779,7 +774,7 @@ update_db_info(PGconn *conn)
779774
static int
780775
connectMakeNonblocking(PGconn *conn)
781776
{
782-
if (FCNTL_NONBLOCK(conn->sock) < 0)
777+
if (!set_noblock(conn->sock))
783778
{
784779
char sebuf[256];
785780

src/port/noblock.c

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* noblock.c
4+
* set a file descriptor as non-blocking
5+
*
6+
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
* IDENTIFICATION
10+
* $PostgreSQL: pgsql/src/port/noblock.c,v 1.1 2004/03/10 21:12:49 momjian Exp $
11+
*
12+
*-------------------------------------------------------------------------
13+
*/
14+
15+
#include "postgres.h"
16+
17+
#include <sys/types.h>
18+
#include <fcntl.h>
19+
20+
bool set_noblock(int sock)
21+
{
22+
#if !defined(WIN32) && !defined(__BEOS__)
23+
return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
24+
#else
25+
long ioctlsocket_ret = 1;
26+
27+
/* Returns non-0 on failure, while fcntl() returns -1 on failure */
28+
#ifdef WIN32
29+
return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
30+
#endif
31+
#ifdef __BEOS__
32+
return (ioctl(sock, FIONBIO, &ioctlsocket_ret) == 0);
33+
#endif
34+
#endif
35+
}

0 commit comments

Comments
 (0)