# -*-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,
#
# 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
*
* 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"
* 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(),
* 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(),
*
*
* 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
*
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;
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);
* 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 $
*
*-------------------------------------------------------------------------
*/
#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
* 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 $
*
*-------------------------------------------------------------------------
*/
#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);
#
# 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 $
#
#-------------------------------------------------------------------------
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
# 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/%
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
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#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
static int
connectMakeNonblocking(PGconn *conn)
{
- if (FCNTL_NONBLOCK(conn->sock) < 0)
+ if (!set_noblock(conn->sock))
{
char sebuf[256];
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * 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
+}