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

Commit 87091cb

Browse files
committed
Create typedef pgsocket for storing socket descriptors.
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.
1 parent 84b6d5f commit 87091cb

File tree

9 files changed

+61
-52
lines changed

9 files changed

+61
-52
lines changed

src/backend/libpq/auth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.190 2010/01/02 16:57:45 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.191 2010/01/10 14:16:07 mha Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1497,7 +1497,7 @@ ident_inet(const SockAddr remote_addr,
14971497
const SockAddr local_addr,
14981498
char *ident_user)
14991499
{
1500-
int sock_fd, /* File descriptor for socket on which we talk
1500+
pgsocket sock_fd, /* File descriptor for socket on which we talk
15011501
* to Ident */
15021502
rc; /* Return code from a locally called function */
15031503
bool ident_return;

src/backend/libpq/ip.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.49 2010/01/02 16:57:45 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.50 2010/01/10 14:16:07 mha Exp $
1212
*
1313
* This file and the IPV6 implementation were initially provided by
1414
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
@@ -656,9 +656,9 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
656656
struct sockaddr *addr, *mask;
657657
char *ptr, *buffer = NULL;
658658
size_t n_buffer = 1024;
659-
int sock, fd;
659+
pgsocket sock, fd;
660660
#ifdef HAVE_IPV6
661-
int sock6;
661+
pgsocket sock6;
662662
#endif
663663
int i, total;
664664

src/backend/libpq/pqcomm.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
3131
* Portions Copyright (c) 1994, Regents of the University of California
3232
*
33-
* $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.200 2010/01/02 16:57:45 momjian Exp $
33+
* $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.201 2010/01/10 14:16:07 mha Exp $
3434
*
3535
*-------------------------------------------------------------------------
3636
*/
@@ -199,9 +199,9 @@ pq_close(int code, Datum arg)
199199
* transport layer reports connection closure, and you can be sure the
200200
* backend has exited.
201201
*
202-
* We do set sock to -1 to prevent any further I/O, though.
202+
* We do set sock to PGINVALID_SOCKET to prevent any further I/O, though.
203203
*/
204-
MyProcPort->sock = -1;
204+
MyProcPort->sock = PGINVALID_SOCKET;
205205
}
206206
}
207207

@@ -232,18 +232,18 @@ StreamDoUnlink(int code, Datum arg)
232232
* StreamServerPort -- open a "listening" port to accept connections.
233233
*
234234
* Successfully opened sockets are added to the ListenSocket[] array,
235-
* at the first position that isn't -1.
235+
* at the first position that isn't PGINVALID_SOCKET.
236236
*
237237
* RETURNS: STATUS_OK or STATUS_ERROR
238238
*/
239239

240240
int
241241
StreamServerPort(int family, char *hostName, unsigned short portNumber,
242242
char *unixSocketName,
243-
int ListenSocket[], int MaxListen)
243+
pgsocket ListenSocket[], int MaxListen)
244244
{
245-
int fd,
246-
err;
245+
pgsocket fd;
246+
int err;
247247
int maxconn;
248248
int ret;
249249
char portNumberStr[32];
@@ -311,7 +311,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
311311
/* See if there is still room to add 1 more socket. */
312312
for (; listen_index < MaxListen; listen_index++)
313313
{
314-
if (ListenSocket[listen_index] == -1)
314+
if (ListenSocket[listen_index] == PGINVALID_SOCKET)
315315
break;
316316
}
317317
if (listen_index >= MaxListen)
@@ -570,7 +570,7 @@ Setup_AF_UNIX(void)
570570
* RETURNS: STATUS_OK or STATUS_ERROR
571571
*/
572572
int
573-
StreamConnection(int server_fd, Port *port)
573+
StreamConnection(pgsocket server_fd, Port *port)
574574
{
575575
/* accept connection and fill in the client (remote) address */
576576
port->raddr.salen = sizeof(port->raddr.addr);
@@ -676,7 +676,7 @@ StreamConnection(int server_fd, Port *port)
676676
* we do NOT want to send anything to the far end.
677677
*/
678678
void
679-
StreamClose(int sock)
679+
StreamClose(pgsocket sock)
680680
{
681681
closesocket(sock);
682682
}

src/backend/postmaster/pgstat.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
1515
*
16-
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.196 2010/01/02 16:57:50 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.197 2010/01/10 14:16:07 mha Exp $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -130,7 +130,7 @@ PgStat_MsgBgWriter BgWriterStats;
130130
* Local data
131131
* ----------
132132
*/
133-
NON_EXEC_STATIC int pgStatSock = -1;
133+
NON_EXEC_STATIC pgsocket pgStatSock = PGINVALID_SOCKET;
134134

135135
static struct sockaddr_storage pgStatAddr;
136136

@@ -369,7 +369,7 @@ pgstat_init(void)
369369
(errcode_for_socket_access(),
370370
errmsg("could not bind socket for statistics collector: %m")));
371371
closesocket(pgStatSock);
372-
pgStatSock = -1;
372+
pgStatSock = PGINVALID_SOCKET;
373373
continue;
374374
}
375375

@@ -380,7 +380,7 @@ pgstat_init(void)
380380
(errcode_for_socket_access(),
381381
errmsg("could not get address of socket for statistics collector: %m")));
382382
closesocket(pgStatSock);
383-
pgStatSock = -1;
383+
pgStatSock = PGINVALID_SOCKET;
384384
continue;
385385
}
386386

@@ -396,7 +396,7 @@ pgstat_init(void)
396396
(errcode_for_socket_access(),
397397
errmsg("could not connect socket for statistics collector: %m")));
398398
closesocket(pgStatSock);
399-
pgStatSock = -1;
399+
pgStatSock = PGINVALID_SOCKET;
400400
continue;
401401
}
402402

@@ -417,7 +417,7 @@ pgstat_init(void)
417417
(errcode_for_socket_access(),
418418
errmsg("could not send test message on socket for statistics collector: %m")));
419419
closesocket(pgStatSock);
420-
pgStatSock = -1;
420+
pgStatSock = PGINVALID_SOCKET;
421421
continue;
422422
}
423423

@@ -443,7 +443,7 @@ pgstat_init(void)
443443
(errcode_for_socket_access(),
444444
errmsg("select() failed in statistics collector: %m")));
445445
closesocket(pgStatSock);
446-
pgStatSock = -1;
446+
pgStatSock = PGINVALID_SOCKET;
447447
continue;
448448
}
449449
if (sel_res == 0 || !FD_ISSET(pgStatSock, &rset))
@@ -458,7 +458,7 @@ pgstat_init(void)
458458
(errcode(ERRCODE_CONNECTION_FAILURE),
459459
errmsg("test message did not get through on socket for statistics collector")));
460460
closesocket(pgStatSock);
461-
pgStatSock = -1;
461+
pgStatSock = PGINVALID_SOCKET;
462462
continue;
463463
}
464464

@@ -473,7 +473,7 @@ pgstat_init(void)
473473
(errcode_for_socket_access(),
474474
errmsg("could not receive test message on socket for statistics collector: %m")));
475475
closesocket(pgStatSock);
476-
pgStatSock = -1;
476+
pgStatSock = PGINVALID_SOCKET;
477477
continue;
478478
}
479479

@@ -483,7 +483,7 @@ pgstat_init(void)
483483
(errcode(ERRCODE_INTERNAL_ERROR),
484484
errmsg("incorrect test message transmission on socket for statistics collector")));
485485
closesocket(pgStatSock);
486-
pgStatSock = -1;
486+
pgStatSock = PGINVALID_SOCKET;
487487
continue;
488488
}
489489

@@ -521,7 +521,7 @@ pgstat_init(void)
521521

522522
if (pgStatSock >= 0)
523523
closesocket(pgStatSock);
524-
pgStatSock = -1;
524+
pgStatSock = PGINVALID_SOCKET;
525525

526526
/*
527527
* Adjust GUC variables to suppress useless activity, and for debugging

src/backend/postmaster/postmaster.c

Lines changed: 14 additions & 14 deletions
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.599 2010/01/02 16:57:50 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.600 2010/01/10 14:16:08 mha Exp $
4141
*
4242
* NOTES
4343
*
@@ -172,7 +172,7 @@ int ReservedBackends;
172172

173173
/* The socket(s) we're listening to. */
174174
#define MAXLISTEN 64
175-
static int ListenSocket[MAXLISTEN];
175+
static pgsocket ListenSocket[MAXLISTEN];
176176

177177
/*
178178
* Set by the -o option
@@ -382,7 +382,7 @@ static pid_t internal_forkexec(int argc, char *argv[], Port *port);
382382
#ifdef WIN32
383383
typedef struct
384384
{
385-
SOCKET origsocket; /* Original socket value, or -1 if not a
385+
SOCKET origsocket; /* Original socket value, or PGINVALID_SOCKET if not a
386386
* socket */
387387
WSAPROTOCOL_INFO wsainfo;
388388
} InheritableSocket;
@@ -400,7 +400,7 @@ typedef struct
400400
Port port;
401401
InheritableSocket portsocket;
402402
char DataDir[MAXPGPATH];
403-
int ListenSocket[MAXLISTEN];
403+
pgsocket ListenSocket[MAXLISTEN];
404404
long MyCancelKey;
405405
int MyPMChildSlot;
406406
#ifndef WIN32
@@ -807,7 +807,7 @@ PostmasterMain(int argc, char *argv[])
807807
* Establish input sockets.
808808
*/
809809
for (i = 0; i < MAXLISTEN; i++)
810-
ListenSocket[i] = -1;
810+
ListenSocket[i] = PGINVALID_SOCKET;
811811

812812
if (ListenAddresses)
813813
{
@@ -860,7 +860,7 @@ PostmasterMain(int argc, char *argv[])
860860

861861
#ifdef USE_BONJOUR
862862
/* Register for Bonjour only if we opened TCP socket(s) */
863-
if (enable_bonjour && ListenSocket[0] != -1)
863+
if (enable_bonjour && ListenSocket[0] != PGINVALID_SOCKET)
864864
{
865865
DNSServiceErrorType err;
866866

@@ -908,7 +908,7 @@ PostmasterMain(int argc, char *argv[])
908908
/*
909909
* check that we have some socket to listen on
910910
*/
911-
if (ListenSocket[0] == -1)
911+
if (ListenSocket[0] == PGINVALID_SOCKET)
912912
ereport(FATAL,
913913
(errmsg("no socket created for listening")));
914914

@@ -1392,7 +1392,7 @@ ServerLoop(void)
13921392

13931393
for (i = 0; i < MAXLISTEN; i++)
13941394
{
1395-
if (ListenSocket[i] == -1)
1395+
if (ListenSocket[i] == PGINVALID_SOCKET)
13961396
break;
13971397
if (FD_ISSET(ListenSocket[i], &rmask))
13981398
{
@@ -1493,7 +1493,7 @@ initMasks(fd_set *rmask)
14931493
{
14941494
int fd = ListenSocket[i];
14951495

1496-
if (fd == -1)
1496+
if (fd == PGINVALID_SOCKET)
14971497
break;
14981498
FD_SET (fd, rmask);
14991499

@@ -2002,10 +2002,10 @@ ClosePostmasterPorts(bool am_syslogger)
20022002
/* Close the listen sockets */
20032003
for (i = 0; i < MAXLISTEN; i++)
20042004
{
2005-
if (ListenSocket[i] != -1)
2005+
if (ListenSocket[i] != PGINVALID_SOCKET)
20062006
{
20072007
StreamClose(ListenSocket[i]);
2008-
ListenSocket[i] = -1;
2008+
ListenSocket[i] = PGINVALID_SOCKET;
20092009
}
20102010
}
20112011

@@ -4408,7 +4408,7 @@ extern slock_t *ProcStructLock;
44084408
extern PROC_HDR *ProcGlobal;
44094409
extern PGPROC *AuxiliaryProcs;
44104410
extern PMSignalData *PMSignalState;
4411-
extern int pgStatSock;
4411+
extern pgsocket pgStatSock;
44124412

44134413
#ifndef WIN32
44144414
#define write_inheritable_socket(dest, src, childpid) ((*(dest) = (src)), true)
@@ -4522,7 +4522,7 @@ static bool
45224522
write_inheritable_socket(InheritableSocket *dest, SOCKET src, pid_t childpid)
45234523
{
45244524
dest->origsocket = src;
4525-
if (src != 0 && src != -1)
4525+
if (src != 0 && src != PGINVALID_SOCKET)
45264526
{
45274527
/* Actual socket */
45284528
if (WSADuplicateSocket(src, childpid, &dest->wsainfo) != 0)
@@ -4544,7 +4544,7 @@ read_inheritable_socket(SOCKET *dest, InheritableSocket *src)
45444544
{
45454545
SOCKET s;
45464546

4547-
if (src->origsocket == -1 || src->origsocket == 0)
4547+
if (src->origsocket == PGINVALID_SOCKET || src->origsocket == 0)
45484548
{
45494549
/* Not a real socket! */
45504550
*dest = src->origsocket;

src/include/libpq/libpq-be.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $PostgreSQL: pgsql/src/include/libpq/libpq-be.h,v 1.72 2010/01/02 16:58:04 momjian Exp $
14+
* $PostgreSQL: pgsql/src/include/libpq/libpq-be.h,v 1.73 2010/01/10 14:16:08 mha Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -103,7 +103,7 @@ typedef struct
103103

104104
typedef struct Port
105105
{
106-
int sock; /* File descriptor */
106+
pgsocket sock; /* File descriptor */
107107
ProtocolVersion proto; /* FE/BE protocol version */
108108
SockAddr laddr; /* local addr (postmaster) */
109109
SockAddr raddr; /* remote addr (client) */

src/include/libpq/libpq.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/libpq/libpq.h,v 1.72 2010/01/02 16:58:04 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/libpq/libpq.h,v 1.73 2010/01/10 14:16:08 mha Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -45,10 +45,10 @@ typedef struct
4545
* prototypes for functions in pqcomm.c
4646
*/
4747
extern int StreamServerPort(int family, char *hostName,
48-
unsigned short portNumber, char *unixSocketName, int ListenSocket[],
48+
unsigned short portNumber, char *unixSocketName, pgsocket ListenSocket[],
4949
int MaxListen);
50-
extern int StreamConnection(int server_fd, Port *port);
51-
extern void StreamClose(int sock);
50+
extern int StreamConnection(pgsocket server_fd, Port *port);
51+
extern void StreamClose(pgsocket sock);
5252
extern void TouchSocketFile(void);
5353
extern void pq_init(void);
5454
extern void pq_comm_reset(void);

0 commit comments

Comments
 (0)