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

Commit db7e46a

Browse files
committed
Use closesocket() for all socket/pipe closing, because Win32 requires
it, and map that to close() on Unix.
1 parent 5f677af commit db7e46a

File tree

8 files changed

+33
-52
lines changed

8 files changed

+33
-52
lines changed

src/backend/libpq/hba.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.99 2003/04/17 22:26:01 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.100 2003/04/25 01:24:00 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -1212,7 +1212,7 @@ ident_inet(const struct in_addr remote_ip_addr,
12121212
ident_user);
12131213
}
12141214
}
1215-
close(sock_fd);
1215+
closesocket(sock_fd);
12161216
}
12171217
}
12181218
return ident_return;

src/backend/libpq/pqcomm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
3131
* Portions Copyright (c) 1994, Regents of the University of California
3232
*
33-
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.151 2003/04/22 00:08:06 tgl Exp $
33+
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.152 2003/04/25 01:24:00 momjian Exp $
3434
*
3535
*-------------------------------------------------------------------------
3636
*/
@@ -150,7 +150,7 @@ pq_close(void)
150150
if (MyProcPort != NULL)
151151
{
152152
secure_close(MyProcPort);
153-
close(MyProcPort->sock);
153+
closesocket(MyProcPort->sock);
154154
/* make sure any subsequent attempts to do I/O fail cleanly */
155155
MyProcPort->sock = -1;
156156
}
@@ -228,7 +228,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
228228
snprintf(portNumberStr, sizeof(portNumberStr), "%d", portNumber);
229229
service = portNumberStr;
230230
}
231-
231+
232232
ret = getaddrinfo2(hostName, service, &hint, &addrs);
233233
if (ret || addrs == NULL)
234234
{
@@ -470,7 +470,7 @@ StreamConnection(int server_fd, Port *port)
470470
void
471471
StreamClose(int sock)
472472
{
473-
close(sock);
473+
closesocket(sock);
474474
}
475475

476476
/*

src/backend/postmaster/pgstat.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* Copyright (c) 2001, PostgreSQL Global Development Group
1818
*
19-
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.32 2003/03/20 03:34:56 momjian Exp $
19+
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.33 2003/04/25 01:24:00 momjian Exp $
2020
* ----------
2121
*/
2222
#include "postgres.h"
@@ -235,7 +235,7 @@ pgstat_init(void)
235235

236236
startup_failed:
237237
if (pgStatSock >= 0)
238-
close(pgStatSock);
238+
closesocket(pgStatSock);
239239
pgStatSock = -1;
240240

241241
/* Adjust GUC variables to suppress useless activity */
@@ -359,10 +359,10 @@ void
359359
pgstat_close_sockets(void)
360360
{
361361
if (pgStatPmPipe[0] >= 0)
362-
close(pgStatPmPipe[0]);
362+
closesocket(pgStatPmPipe[0]);
363363
pgStatPmPipe[0] = -1;
364364
if (pgStatPmPipe[1] >= 0)
365-
close(pgStatPmPipe[1]);
365+
closesocket(pgStatPmPipe[1]);
366366
pgStatPmPipe[1] = -1;
367367
}
368368

@@ -1120,7 +1120,7 @@ pgstat_main(void)
11201120
* Close the writing end of the postmaster pipe, so we'll see it
11211121
* closing when the postmaster terminates and can terminate as well.
11221122
*/
1123-
close(pgStatPmPipe[1]);
1123+
closesocket(pgStatPmPipe[1]);
11241124
pgStatPmPipe[1] = -1;
11251125

11261126
/*
@@ -1167,13 +1167,13 @@ pgstat_main(void)
11671167

11681168
case 0:
11691169
/* child becomes collector process */
1170-
close(pgStatPipe[1]);
1171-
close(pgStatSock);
1170+
closesocket(pgStatPipe[1]);
1171+
closesocket(pgStatSock);
11721172
break;
11731173

11741174
default:
11751175
/* parent becomes buffer process */
1176-
close(pgStatPipe[0]);
1176+
closesocket(pgStatPipe[0]);
11771177
pgstat_recvbuffer();
11781178
exit(0);
11791179
}

src/include/c.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: c.h,v 1.139 2003/04/22 02:18:09 momjian Exp $
15+
* $Id: c.h,v 1.140 2003/04/25 01:24:00 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -721,6 +721,13 @@ int pgunlink(const char *path);
721721
#define unlink(from, to) pgunlink(from, to)
722722
#endif
723723

724+
/*
725+
* Win32 requires a special close for sockets and pipes, while on Unix
726+
* close() does them all.
727+
*/
728+
#ifndef WIN32
729+
#define closesocket close
730+
#endif
724731

725732
/* These are for things that are one way on Unix and another on NT */
726733
#define NULL_DEV "/dev/null"

src/interfaces/libpq/fe-connect.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.235 2003/04/24 21:16:44 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.236 2003/04/25 01:24:00 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -956,7 +956,7 @@ connectDBStart(PGconn *conn)
956956
/* ignore connect() failure if we have more addrs to try */
957957
if (addr_cur->ai_next != NULL)
958958
{
959-
close(conn->sock);
959+
closesocket(conn->sock);
960960
conn->sock = -1;
961961
continue;
962962
}
@@ -1015,11 +1015,7 @@ connectDBStart(PGconn *conn)
10151015
if (conn->Pfdebug)
10161016
fprintf(conn->Pfdebug, "Postmaster reports error, attempting fallback to pre-7.0.\n");
10171017
pqsecure_close(conn);
1018-
#ifdef WIN32
10191018
closesocket(conn->sock);
1020-
#else
1021-
close(conn->sock);
1022-
#endif
10231019
conn->sock = -1;
10241020
conn->allow_ssl_try = FALSE;
10251021
return connectDBStart(conn);
@@ -1056,11 +1052,7 @@ connectDBStart(PGconn *conn)
10561052
if (conn->sock >= 0)
10571053
{
10581054
pqsecure_close(conn);
1059-
#ifdef WIN32
10601055
closesocket(conn->sock);
1061-
#else
1062-
close(conn->sock);
1063-
#endif
10641056
conn->sock = -1;
10651057
}
10661058
conn->status = CONNECTION_BAD;
@@ -1928,11 +1920,7 @@ freePGconn(PGconn *conn)
19281920
if (conn->sock >= 0)
19291921
{
19301922
pqsecure_close(conn);
1931-
#ifdef WIN32
19321923
closesocket(conn->sock);
1933-
#else
1934-
close(conn->sock);
1935-
#endif
19361924
}
19371925
if (conn->pghost)
19381926
free(conn->pghost);
@@ -2003,11 +1991,7 @@ closePGconn(PGconn *conn)
20031991
if (conn->sock >= 0)
20041992
{
20051993
pqsecure_close(conn);
2006-
#ifdef WIN32
20071994
closesocket(conn->sock);
2008-
#else
2009-
close(conn->sock);
2010-
#endif
20111995
}
20121996
conn->sock = -1;
20131997
conn->status = CONNECTION_BAD; /* Well, not really _bad_ - just
@@ -2187,11 +2171,10 @@ PQrequestCancel(PGconn *conn)
21872171
}
21882172

21892173
/* Sent it, done */
2190-
#ifdef WIN32
21912174
closesocket(tmpsock);
2175+
#ifdef WIN32
21922176
WSASetLastError(save_errno);
21932177
#else
2194-
close(tmpsock);
21952178
errno = save_errno;
21962179
#endif
21972180

@@ -2203,11 +2186,10 @@ PQrequestCancel(PGconn *conn)
22032186
conn->errorMessage.len = strlen(conn->errorMessage.data);
22042187
if (tmpsock >= 0)
22052188
{
2206-
#ifdef WIN32
22072189
closesocket(tmpsock);
2190+
#ifdef WIN32
22082191
WSASetLastError(save_errno);
22092192
#else
2210-
close(tmpsock);
22112193
errno = save_errno;
22122194
#endif
22132195
}

src/interfaces/libpq/fe-exec.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.131 2003/04/24 21:16:44 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.132 2003/04/25 01:24:00 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1161,11 +1161,7 @@ handleSyncLoss(PGconn *conn, char id, int msgLength)
11611161
id, msgLength);
11621162
conn->status = CONNECTION_BAD; /* No more connection to backend */
11631163
pqsecure_close(conn);
1164-
#ifdef WIN32
11651164
closesocket(conn->sock);
1166-
#else
1167-
close(conn->sock);
1168-
#endif
11691165
conn->sock = -1;
11701166
}
11711167

src/interfaces/libpq/fe-misc.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1994, Regents of the University of California
2424
*
2525
* IDENTIFICATION
26-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.90 2003/04/22 00:08:07 tgl Exp $
26+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.91 2003/04/25 01:24:00 momjian Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -681,11 +681,7 @@ pqReadData(PGconn *conn)
681681
"\tbefore or while processing the request.\n"));
682682
conn->status = CONNECTION_BAD; /* No more connection to backend */
683683
pqsecure_close(conn);
684-
#ifdef WIN32
685684
closesocket(conn->sock);
686-
#else
687-
close(conn->sock);
688-
#endif
689685
conn->sock = -1;
690686

691687
return -1;

src/interfaces/python/pgmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,10 +2405,10 @@ pg_inserttable(pgobject * self, PyObject * args)
24052405
n = j; /* never used before this assignment */
24062406
}
24072407
if (n)
2408-
{
2408+
{
24092409
/* allocate buffer */
24102410
if (!(buffer = malloc(MAX_BUFFER_SIZE)))
2411-
{
2411+
{
24122412
PyErr_SetString(PyExc_MemoryError,
24132413
"can't allocate insert buffer.");
24142414
return NULL;
@@ -2438,7 +2438,7 @@ pg_inserttable(pgobject * self, PyObject * args)
24382438
getsubitem = PyTuple_GetItem;
24392439
else
24402440
getsubitem = PyList_GetItem;
2441-
2441+
24422442
/* builds insert line */
24432443
bufpt=buffer;
24442444
bufsiz = MAX_BUFFER_SIZE - 1;
@@ -2527,7 +2527,7 @@ pg_inserttable(pgobject * self, PyObject * args)
25272527
{
25282528
*bufpt++ = '\t'; --bufsiz;
25292529
}
2530-
2530+
25312531
if (bufsiz <= 0)
25322532
{
25332533
free(buffer);
@@ -2543,7 +2543,7 @@ pg_inserttable(pgobject * self, PyObject * args)
25432543
/* sends data */
25442544
PQputline(self->cnx, buffer);
25452545
}
2546-
2546+
25472547
/* ends query */
25482548
PQputline(self->cnx, "\\.\n");
25492549
PQendcopy(self->cnx);

0 commit comments

Comments
 (0)