OSDN Git Service

Create typedef pgsocket for storing socket descriptors.
authorMagnus Hagander <magnus@hagander.net>
Sun, 10 Jan 2010 14:16:08 +0000 (14:16 +0000)
committerMagnus Hagander <magnus@hagander.net>
Sun, 10 Jan 2010 14:16:08 +0000 (14:16 +0000)
This silences some warnings on Win64. Not using the proper SOCKET datatype
was actually wrong on Win32 as well, but didn't cause any warnings there.

Also create define PGINVALID_SOCKET to indicate an invalid/non-existing
socket, instead of using a hardcoded -1 value.

src/backend/libpq/auth.c
src/backend/libpq/ip.c
src/backend/libpq/pqcomm.c
src/backend/postmaster/pgstat.c
src/backend/postmaster/postmaster.c
src/include/libpq/libpq-be.h
src/include/libpq/libpq.h
src/include/port.h
src/port/noblock.c

index 4344b0b..e7d0dbb 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.190 2010/01/02 16:57:45 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.191 2010/01/10 14:16:07 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1497,7 +1497,7 @@ ident_inet(const SockAddr remote_addr,
                   const SockAddr local_addr,
                   char *ident_user)
 {
-       int                     sock_fd,                /* File descriptor for socket on which we talk
+       pgsocket        sock_fd,                /* File descriptor for socket on which we talk
                                                                 * to Ident */
                                rc;                             /* Return code from a locally called function */
        bool            ident_return;
index b0085cf..778b9f9 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.49 2010/01/02 16:57:45 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.50 2010/01/10 14:16:07 mha Exp $
  *
  * This file and the IPV6 implementation were initially provided by
  * Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
@@ -656,9 +656,9 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
        struct sockaddr *addr, *mask;
        char *ptr, *buffer = NULL;
        size_t n_buffer = 1024;
-       int sock, fd;
+       pgsocket sock, fd;
 #ifdef HAVE_IPV6
-       int sock6;
+       pgsocket sock6;
 #endif
        int i, total;
 
index 8800fa6..b99c9da 100644 (file)
@@ -30,7 +30,7 @@
  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *     $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.200 2010/01/02 16:57:45 momjian Exp $
+ *     $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.201 2010/01/10 14:16:07 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -199,9 +199,9 @@ pq_close(int code, Datum arg)
                 * transport layer reports connection closure, and you can be sure the
                 * backend has exited.
                 *
-                * We do set sock to -1 to prevent any further I/O, though.
+                * We do set sock to PGINVALID_SOCKET to prevent any further I/O, though.
                 */
-               MyProcPort->sock = -1;
+               MyProcPort->sock = PGINVALID_SOCKET;
        }
 }
 
@@ -232,7 +232,7 @@ StreamDoUnlink(int code, Datum arg)
  * StreamServerPort -- open a "listening" port to accept connections.
  *
  * Successfully opened sockets are added to the ListenSocket[] array,
- * at the first position that isn't -1.
+ * at the first position that isn't PGINVALID_SOCKET.
  *
  * RETURNS: STATUS_OK or STATUS_ERROR
  */
@@ -240,10 +240,10 @@ StreamDoUnlink(int code, Datum arg)
 int
 StreamServerPort(int family, char *hostName, unsigned short portNumber,
                                 char *unixSocketName,
-                                int ListenSocket[], int MaxListen)
+                                pgsocket ListenSocket[], int MaxListen)
 {
-       int                     fd,
-                               err;
+       pgsocket        fd;
+       int                     err;
        int                     maxconn;
        int                     ret;
        char            portNumberStr[32];
@@ -311,7 +311,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
                /* See if there is still room to add 1 more socket. */
                for (; listen_index < MaxListen; listen_index++)
                {
-                       if (ListenSocket[listen_index] == -1)
+                       if (ListenSocket[listen_index] == PGINVALID_SOCKET)
                                break;
                }
                if (listen_index >= MaxListen)
@@ -570,7 +570,7 @@ Setup_AF_UNIX(void)
  * RETURNS: STATUS_OK or STATUS_ERROR
  */
 int
-StreamConnection(int server_fd, Port *port)
+StreamConnection(pgsocket server_fd, Port *port)
 {
        /* accept connection and fill in the client (remote) address */
        port->raddr.salen = sizeof(port->raddr.addr);
@@ -676,7 +676,7 @@ StreamConnection(int server_fd, Port *port)
  * we do NOT want to send anything to the far end.
  */
 void
-StreamClose(int sock)
+StreamClose(pgsocket sock)
 {
        closesocket(sock);
 }
index d5adaf6..e45cdaa 100644 (file)
@@ -13,7 +13,7 @@
  *
  *     Copyright (c) 2001-2010, PostgreSQL Global Development Group
  *
- *     $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.196 2010/01/02 16:57:50 momjian Exp $
+ *     $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.197 2010/01/10 14:16:07 mha Exp $
  * ----------
  */
 #include "postgres.h"
@@ -130,7 +130,7 @@ PgStat_MsgBgWriter BgWriterStats;
  * Local data
  * ----------
  */
-NON_EXEC_STATIC int pgStatSock = -1;
+NON_EXEC_STATIC pgsocket pgStatSock = PGINVALID_SOCKET;
 
 static struct sockaddr_storage pgStatAddr;
 
@@ -369,7 +369,7 @@ pgstat_init(void)
                                        (errcode_for_socket_access(),
                          errmsg("could not bind socket for statistics collector: %m")));
                        closesocket(pgStatSock);
-                       pgStatSock = -1;
+                       pgStatSock = PGINVALID_SOCKET;
                        continue;
                }
 
@@ -380,7 +380,7 @@ pgstat_init(void)
                                        (errcode_for_socket_access(),
                                         errmsg("could not get address of socket for statistics collector: %m")));
                        closesocket(pgStatSock);
-                       pgStatSock = -1;
+                       pgStatSock = PGINVALID_SOCKET;
                        continue;
                }
 
@@ -396,7 +396,7 @@ pgstat_init(void)
                                        (errcode_for_socket_access(),
                        errmsg("could not connect socket for statistics collector: %m")));
                        closesocket(pgStatSock);
-                       pgStatSock = -1;
+                       pgStatSock = PGINVALID_SOCKET;
                        continue;
                }
 
@@ -417,7 +417,7 @@ retry1:
                                        (errcode_for_socket_access(),
                                         errmsg("could not send test message on socket for statistics collector: %m")));
                        closesocket(pgStatSock);
-                       pgStatSock = -1;
+                       pgStatSock = PGINVALID_SOCKET;
                        continue;
                }
 
@@ -443,7 +443,7 @@ retry1:
                                        (errcode_for_socket_access(),
                                         errmsg("select() failed in statistics collector: %m")));
                        closesocket(pgStatSock);
-                       pgStatSock = -1;
+                       pgStatSock = PGINVALID_SOCKET;
                        continue;
                }
                if (sel_res == 0 || !FD_ISSET(pgStatSock, &rset))
@@ -458,7 +458,7 @@ retry1:
                                        (errcode(ERRCODE_CONNECTION_FAILURE),
                                         errmsg("test message did not get through on socket for statistics collector")));
                        closesocket(pgStatSock);
-                       pgStatSock = -1;
+                       pgStatSock = PGINVALID_SOCKET;
                        continue;
                }
 
@@ -473,7 +473,7 @@ retry2:
                                        (errcode_for_socket_access(),
                                         errmsg("could not receive test message on socket for statistics collector: %m")));
                        closesocket(pgStatSock);
-                       pgStatSock = -1;
+                       pgStatSock = PGINVALID_SOCKET;
                        continue;
                }
 
@@ -483,7 +483,7 @@ retry2:
                                        (errcode(ERRCODE_INTERNAL_ERROR),
                                         errmsg("incorrect test message transmission on socket for statistics collector")));
                        closesocket(pgStatSock);
-                       pgStatSock = -1;
+                       pgStatSock = PGINVALID_SOCKET;
                        continue;
                }
 
@@ -521,7 +521,7 @@ startup_failed:
 
        if (pgStatSock >= 0)
                closesocket(pgStatSock);
-       pgStatSock = -1;
+       pgStatSock = PGINVALID_SOCKET;
 
        /*
         * Adjust GUC variables to suppress useless activity, and for debugging
index ca79a2c..94672be 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.599 2010/01/02 16:57:50 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.600 2010/01/10 14:16:08 mha Exp $
  *
  * NOTES
  *
@@ -172,7 +172,7 @@ int                 ReservedBackends;
 
 /* The socket(s) we're listening to. */
 #define MAXLISTEN      64
-static int     ListenSocket[MAXLISTEN];
+static pgsocket ListenSocket[MAXLISTEN];
 
 /*
  * Set by the -o option
@@ -382,7 +382,7 @@ static pid_t internal_forkexec(int argc, char *argv[], Port *port);
 #ifdef WIN32
 typedef struct
 {
-       SOCKET          origsocket;             /* Original socket value, or -1 if not a
+       SOCKET          origsocket;             /* Original socket value, or PGINVALID_SOCKET if not a
                                                                 * socket */
        WSAPROTOCOL_INFO wsainfo;
 } InheritableSocket;
@@ -400,7 +400,7 @@ typedef struct
        Port            port;
        InheritableSocket portsocket;
        char            DataDir[MAXPGPATH];
-       int                     ListenSocket[MAXLISTEN];
+       pgsocket        ListenSocket[MAXLISTEN];
        long            MyCancelKey;
        int                     MyPMChildSlot;
 #ifndef WIN32
@@ -807,7 +807,7 @@ PostmasterMain(int argc, char *argv[])
         * Establish input sockets.
         */
        for (i = 0; i < MAXLISTEN; i++)
-               ListenSocket[i] = -1;
+               ListenSocket[i] = PGINVALID_SOCKET;
 
        if (ListenAddresses)
        {
@@ -860,7 +860,7 @@ PostmasterMain(int argc, char *argv[])
 
 #ifdef USE_BONJOUR
        /* Register for Bonjour only if we opened TCP socket(s) */
-       if (enable_bonjour && ListenSocket[0] != -1)
+       if (enable_bonjour && ListenSocket[0] != PGINVALID_SOCKET)
        {
                DNSServiceErrorType err;
 
@@ -908,7 +908,7 @@ PostmasterMain(int argc, char *argv[])
        /*
         * check that we have some socket to listen on
         */
-       if (ListenSocket[0] == -1)
+       if (ListenSocket[0] == PGINVALID_SOCKET)
                ereport(FATAL,
                                (errmsg("no socket created for listening")));
 
@@ -1392,7 +1392,7 @@ ServerLoop(void)
 
                        for (i = 0; i < MAXLISTEN; i++)
                        {
-                               if (ListenSocket[i] == -1)
+                               if (ListenSocket[i] == PGINVALID_SOCKET)
                                        break;
                                if (FD_ISSET(ListenSocket[i], &rmask))
                                {
@@ -1493,7 +1493,7 @@ initMasks(fd_set *rmask)
        {
                int                     fd = ListenSocket[i];
 
-               if (fd == -1)
+               if (fd == PGINVALID_SOCKET)
                        break;
                FD_SET          (fd, rmask);
 
@@ -2002,10 +2002,10 @@ ClosePostmasterPorts(bool am_syslogger)
        /* Close the listen sockets */
        for (i = 0; i < MAXLISTEN; i++)
        {
-               if (ListenSocket[i] != -1)
+               if (ListenSocket[i] != PGINVALID_SOCKET)
                {
                        StreamClose(ListenSocket[i]);
-                       ListenSocket[i] = -1;
+                       ListenSocket[i] = PGINVALID_SOCKET;
                }
        }
 
@@ -4408,7 +4408,7 @@ extern slock_t *ProcStructLock;
 extern PROC_HDR *ProcGlobal;
 extern PGPROC *AuxiliaryProcs;
 extern PMSignalData *PMSignalState;
-extern int     pgStatSock;
+extern pgsocket pgStatSock;
 
 #ifndef WIN32
 #define write_inheritable_socket(dest, src, childpid) ((*(dest) = (src)), true)
@@ -4522,7 +4522,7 @@ static bool
 write_inheritable_socket(InheritableSocket *dest, SOCKET src, pid_t childpid)
 {
        dest->origsocket = src;
-       if (src != 0 && src != -1)
+       if (src != 0 && src != PGINVALID_SOCKET)
        {
                /* Actual socket */
                if (WSADuplicateSocket(src, childpid, &dest->wsainfo) != 0)
@@ -4544,7 +4544,7 @@ read_inheritable_socket(SOCKET *dest, InheritableSocket *src)
 {
        SOCKET          s;
 
-       if (src->origsocket == -1 || src->origsocket == 0)
+       if (src->origsocket == PGINVALID_SOCKET || src->origsocket == 0)
        {
                /* Not a real socket! */
                *dest = src->origsocket;
index c714add..1d35871 100644 (file)
@@ -11,7 +11,7 @@
  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/libpq/libpq-be.h,v 1.72 2010/01/02 16:58:04 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/libpq/libpq-be.h,v 1.73 2010/01/10 14:16:08 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -103,7 +103,7 @@ typedef struct
 
 typedef struct Port
 {
-       int                     sock;                   /* File descriptor */
+       pgsocket        sock;                   /* File descriptor */
        ProtocolVersion proto;          /* FE/BE protocol version */
        SockAddr        laddr;                  /* local addr (postmaster) */
        SockAddr        raddr;                  /* remote addr (client) */
index 314ce69..c9c7e0d 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/libpq/libpq.h,v 1.72 2010/01/02 16:58:04 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/libpq/libpq.h,v 1.73 2010/01/10 14:16:08 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -45,10 +45,10 @@ typedef struct
  * prototypes for functions in pqcomm.c
  */
 extern int StreamServerPort(int family, char *hostName,
-                unsigned short portNumber, char *unixSocketName, int ListenSocket[],
+                unsigned short portNumber, char *unixSocketName, pgsocket ListenSocket[],
                                 int MaxListen);
-extern int     StreamConnection(int server_fd, Port *port);
-extern void StreamClose(int sock);
+extern int     StreamConnection(pgsocket server_fd, Port *port);
+extern void StreamClose(pgsocket sock);
 extern void TouchSocketFile(void);
 extern void pq_init(void);
 extern void pq_comm_reset(void);
index b5c22cb..2a4f9b4 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/port.h,v 1.128 2010/01/02 16:58:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.129 2010/01/10 14:16:08 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include <netdb.h>
 #include <pwd.h>
 
+/* socket has a different definition on WIN32 */
+#ifndef WIN32
+typedef int pgsocket;
+#define PGINVALID_SOCKET -1
+#else
+typedef SOCKET pgsocket;
+#define PGINVALID_SOCKET INVALID_SOCKET
+#endif
+
 /* non-blocking */
-extern bool pg_set_noblock(int sock);
-extern bool pg_set_block(int sock);
+extern bool pg_set_noblock(pgsocket sock);
+extern bool pg_set_block(pgsocket sock);
 
 /* Portable path handling for Unix/Win32 (in path.c) */
 
index 5349e9e..ace3bfd 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/port/noblock.c,v 1.14 2010/01/02 16:58:13 momjian Exp $
+ *       $PostgreSQL: pgsql/src/port/noblock.c,v 1.15 2010/01/10 14:16:08 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,7 +18,7 @@
 
 
 bool
-pg_set_noblock(int sock)
+pg_set_noblock(pgsocket sock)
 {
 #if !defined(WIN32)
        return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
@@ -32,7 +32,7 @@ pg_set_noblock(int sock)
 
 
 bool
-pg_set_block(int sock)
+pg_set_block(pgsocket sock)
 {
 #if !defined(WIN32)
        int                     flags;