Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f0aff0

Browse files
committed
Remove calls to getprotobyname(), which we now know leaks memory on
some platforms --- and I also see that it is documented as not thread-safe on HPUX and possibly other platforms. No good reason not to justuse IPPROTO_TCP constant from <netinet/in.h> instead.
1 parent9dab9ab commit1f0aff0

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

‎src/backend/libpq/pqcomm.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
3030
* Portions Copyright (c) 1994, Regents of the University of California
3131
*
32-
*$Id: pqcomm.c,v 1.90 2000/05/20 13:10:54 ishii Exp $
32+
*$Id: pqcomm.c,v 1.91 2000/05/21 21:19:53 tgl Exp $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -360,19 +360,12 @@ StreamConnection(int server_fd, Port *port)
360360
returnSTATUS_ERROR;
361361
}
362362

363-
/* selectTCP_NODELAY option if it's a TCP connection */
363+
/* selectNODELAY and KEEPALIVE options if it's a TCP connection */
364364
if (port->laddr.sa.sa_family==AF_INET)
365365
{
366-
structprotoent*pe;
367366
inton=1;
368367

369-
pe=getprotobyname("TCP");
370-
if (pe==NULL)
371-
{
372-
perror("postmaster: StreamConnection: getprotobyname");
373-
returnSTATUS_ERROR;
374-
}
375-
if (setsockopt(port->sock,pe->p_proto,TCP_NODELAY,
368+
if (setsockopt(port->sock,IPPROTO_TCP,TCP_NODELAY,
376369
&on,sizeof(on))<0)
377370
{
378371
perror("postmaster: StreamConnection: setsockopt(TCP_NODELAY)");

‎src/interfaces/libpq/fe-connect.c

Lines changed: 3 additions & 12 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.126 2000/04/12 17:17:14 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.127 2000/05/21 21:19:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -29,6 +29,7 @@
2929
#include<sys/socket.h>
3030
#include<unistd.h>
3131
#include<netdb.h>
32+
#include<netinet/in.h>
3233
#include<netinet/tcp.h>
3334
#include<arpa/inet.h>
3435
#endif
@@ -625,19 +626,9 @@ connectMakeNonblocking(PGconn *conn)
625626
staticint
626627
connectNoDelay(PGconn*conn)
627628
{
628-
structprotoent*pe;
629629
inton=1;
630630

631-
pe=getprotobyname("TCP");
632-
if (pe==NULL)
633-
{
634-
printfPQExpBuffer(&conn->errorMessage,
635-
"connectNoDelay() -- "
636-
"getprotobyname failed: errno=%d\n%s\n",
637-
errno,strerror(errno));
638-
return0;
639-
}
640-
if (setsockopt(conn->sock,pe->p_proto,TCP_NODELAY,
631+
if (setsockopt(conn->sock,IPPROTO_TCP,TCP_NODELAY,
641632
#ifdefWIN32
642633
(char*)
643634
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp