*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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;
*
*
* 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
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;
* 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 $
*
*-------------------------------------------------------------------------
*/
* 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;
}
}
* 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
*/
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];
/* 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)
* 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);
* we do NOT want to send anything to the far end.
*/
void
-StreamClose(int sock)
+StreamClose(pgsocket sock)
{
closesocket(sock);
}
*
* 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"
* Local data
* ----------
*/
-NON_EXEC_STATIC int pgStatSock = -1;
+NON_EXEC_STATIC pgsocket pgStatSock = PGINVALID_SOCKET;
static struct sockaddr_storage pgStatAddr;
(errcode_for_socket_access(),
errmsg("could not bind socket for statistics collector: %m")));
closesocket(pgStatSock);
- pgStatSock = -1;
+ pgStatSock = PGINVALID_SOCKET;
continue;
}
(errcode_for_socket_access(),
errmsg("could not get address of socket for statistics collector: %m")));
closesocket(pgStatSock);
- pgStatSock = -1;
+ pgStatSock = PGINVALID_SOCKET;
continue;
}
(errcode_for_socket_access(),
errmsg("could not connect socket for statistics collector: %m")));
closesocket(pgStatSock);
- pgStatSock = -1;
+ pgStatSock = PGINVALID_SOCKET;
continue;
}
(errcode_for_socket_access(),
errmsg("could not send test message on socket for statistics collector: %m")));
closesocket(pgStatSock);
- pgStatSock = -1;
+ pgStatSock = PGINVALID_SOCKET;
continue;
}
(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))
(errcode(ERRCODE_CONNECTION_FAILURE),
errmsg("test message did not get through on socket for statistics collector")));
closesocket(pgStatSock);
- pgStatSock = -1;
+ pgStatSock = PGINVALID_SOCKET;
continue;
}
(errcode_for_socket_access(),
errmsg("could not receive test message on socket for statistics collector: %m")));
closesocket(pgStatSock);
- pgStatSock = -1;
+ pgStatSock = PGINVALID_SOCKET;
continue;
}
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("incorrect test message transmission on socket for statistics collector")));
closesocket(pgStatSock);
- pgStatSock = -1;
+ pgStatSock = PGINVALID_SOCKET;
continue;
}
if (pgStatSock >= 0)
closesocket(pgStatSock);
- pgStatSock = -1;
+ pgStatSock = PGINVALID_SOCKET;
/*
* Adjust GUC variables to suppress useless activity, and for debugging
*
*
* 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
*
/* The socket(s) we're listening to. */
#define MAXLISTEN 64
-static int ListenSocket[MAXLISTEN];
+static pgsocket ListenSocket[MAXLISTEN];
/*
* Set by the -o option
#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;
Port port;
InheritableSocket portsocket;
char DataDir[MAXPGPATH];
- int ListenSocket[MAXLISTEN];
+ pgsocket ListenSocket[MAXLISTEN];
long MyCancelKey;
int MyPMChildSlot;
#ifndef WIN32
* Establish input sockets.
*/
for (i = 0; i < MAXLISTEN; i++)
- ListenSocket[i] = -1;
+ ListenSocket[i] = PGINVALID_SOCKET;
if (ListenAddresses)
{
#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;
/*
* 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")));
for (i = 0; i < MAXLISTEN; i++)
{
- if (ListenSocket[i] == -1)
+ if (ListenSocket[i] == PGINVALID_SOCKET)
break;
if (FD_ISSET(ListenSocket[i], &rmask))
{
{
int fd = ListenSocket[i];
- if (fd == -1)
+ if (fd == PGINVALID_SOCKET)
break;
FD_SET (fd, rmask);
/* 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;
}
}
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)
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)
{
SOCKET s;
- if (src->origsocket == -1 || src->origsocket == 0)
+ if (src->origsocket == PGINVALID_SOCKET || src->origsocket == 0)
{
/* Not a real socket! */
*dest = src->origsocket;
* 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 $
*
*-------------------------------------------------------------------------
*/
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) */
* 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 $
*
*-------------------------------------------------------------------------
*/
* 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);
* 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) */
* 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 $
*
*-------------------------------------------------------------------------
*/
bool
-pg_set_noblock(int sock)
+pg_set_noblock(pgsocket sock)
{
#if !defined(WIN32)
return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
bool
-pg_set_block(int sock)
+pg_set_block(pgsocket sock)
{
#if !defined(WIN32)
int flags;