mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
Remove now redundant pgpipe code.
This commit is contained in:
parent
7313cc0163
commit
d2c1740dc2
@ -1,95 +0,0 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pipe.c
|
||||
* pipe()
|
||||
*
|
||||
* Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
*
|
||||
* This is a replacement version of pipe for Win32 which allows
|
||||
* returned handles to be used in select(). Note that read/write calls
|
||||
* must be replaced with recv/send.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* src/backend/port/pipe.c
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#ifdef WIN32
|
||||
int
|
||||
pgpipe(int handles[2])
|
||||
{
|
||||
SOCKET s;
|
||||
struct sockaddr_in serv_addr;
|
||||
int len = sizeof(serv_addr);
|
||||
|
||||
handles[0] = handles[1] = INVALID_SOCKET;
|
||||
|
||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
|
||||
{
|
||||
ereport(LOG, (errmsg_internal("pgpipe could not create socket: %ui", WSAGetLastError())));
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset((void *) &serv_addr, 0, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_port = htons(0);
|
||||
serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
if (bind(s, (SOCKADDR *) &serv_addr, len) == SOCKET_ERROR)
|
||||
{
|
||||
ereport(LOG, (errmsg_internal("pgpipe could not bind: %ui", WSAGetLastError())));
|
||||
closesocket(s);
|
||||
return -1;
|
||||
}
|
||||
if (listen(s, 1) == SOCKET_ERROR)
|
||||
{
|
||||
ereport(LOG, (errmsg_internal("pgpipe could not listen: %ui", WSAGetLastError())));
|
||||
closesocket(s);
|
||||
return -1;
|
||||
}
|
||||
if (getsockname(s, (SOCKADDR *) &serv_addr, &len) == SOCKET_ERROR)
|
||||
{
|
||||
ereport(LOG, (errmsg_internal("pgpipe could not getsockname: %ui", WSAGetLastError())));
|
||||
closesocket(s);
|
||||
return -1;
|
||||
}
|
||||
if ((handles[1] = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
|
||||
{
|
||||
ereport(LOG, (errmsg_internal("pgpipe could not create socket 2: %ui", WSAGetLastError())));
|
||||
closesocket(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connect(handles[1], (SOCKADDR *) &serv_addr, len) == SOCKET_ERROR)
|
||||
{
|
||||
ereport(LOG, (errmsg_internal("pgpipe could not connect socket: %ui", WSAGetLastError())));
|
||||
closesocket(s);
|
||||
return -1;
|
||||
}
|
||||
if ((handles[0] = accept(s, (SOCKADDR *) &serv_addr, &len)) == INVALID_SOCKET)
|
||||
{
|
||||
ereport(LOG, (errmsg_internal("pgpipe could not accept socket: %ui", WSAGetLastError())));
|
||||
closesocket(handles[1]);
|
||||
handles[1] = INVALID_SOCKET;
|
||||
closesocket(s);
|
||||
return -1;
|
||||
}
|
||||
closesocket(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
piperead(int s, char *buf, int len)
|
||||
{
|
||||
int ret = recv(s, buf, len, 0);
|
||||
|
||||
if (ret < 0 && WSAGetLastError() == WSAECONNRESET)
|
||||
/* EOF on the pipe! (win32 socket based implementation) */
|
||||
ret = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
@ -391,9 +391,9 @@ SysLoggerMain(int argc, char *argv[])
|
||||
}
|
||||
else if (rc > 0 && FD_ISSET(syslogPipe[0], &rfds))
|
||||
{
|
||||
bytesRead = piperead(syslogPipe[0],
|
||||
logbuffer + bytes_in_logbuffer,
|
||||
sizeof(logbuffer) - bytes_in_logbuffer);
|
||||
bytesRead = read(syslogPipe[0],
|
||||
logbuffer + bytes_in_logbuffer,
|
||||
sizeof(logbuffer) - bytes_in_logbuffer);
|
||||
if (bytesRead < 0)
|
||||
{
|
||||
if (errno != EINTR)
|
||||
@ -487,7 +487,7 @@ SysLogger_Start(void)
|
||||
#ifndef WIN32
|
||||
if (syslogPipe[0] < 0)
|
||||
{
|
||||
if (pgpipe(syslogPipe) < 0)
|
||||
if (pipe(syslogPipe) < 0)
|
||||
ereport(FATAL,
|
||||
(errcode_for_socket_access(),
|
||||
(errmsg("could not create pipe for syslog: %m"))));
|
||||
|
@ -162,7 +162,7 @@ segment_callback(XLogRecPtr segendpos, uint32 timeline)
|
||||
char xlogend[64];
|
||||
|
||||
MemSet(xlogend, 0, sizeof(xlogend));
|
||||
r = piperead(bgpipe[0], xlogend, sizeof(xlogend));
|
||||
r = read(bgpipe[0], xlogend, sizeof(xlogend));
|
||||
if (r < 0)
|
||||
{
|
||||
fprintf(stderr, _("%s: could not read from ready pipe: %s\n"),
|
||||
@ -270,7 +270,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier)
|
||||
|
||||
#ifndef WIN32
|
||||
/* Create our background pipe */
|
||||
if (pgpipe(bgpipe) < 0)
|
||||
if (pipe(bgpipe) < 0)
|
||||
{
|
||||
fprintf(stderr, _("%s: could not create pipe for background process: %s\n"),
|
||||
progname, strerror(errno));
|
||||
@ -1094,7 +1094,7 @@ BaseBackup(void)
|
||||
fprintf(stderr, _("%s: waiting for background process to finish streaming...\n"), progname);
|
||||
|
||||
#ifndef WIN32
|
||||
if (pipewrite(bgpipe[1], xlogend, strlen(xlogend)) != strlen(xlogend))
|
||||
if (write(bgpipe[1], xlogend, strlen(xlogend)) != strlen(xlogend))
|
||||
{
|
||||
fprintf(stderr, _("%s: could not send command to background pipe: %s\n"),
|
||||
progname, strerror(errno));
|
||||
|
@ -250,26 +250,7 @@ extern char *pgwin32_setlocale(int category, const char *locale);
|
||||
/* Portable prompt handling */
|
||||
extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
|
||||
|
||||
/*
|
||||
* WIN32 doesn't allow descriptors returned by pipe() to be used in select(),
|
||||
* so for that platform we use socket() instead of pipe().
|
||||
* There is some inconsistency here because sometimes we require pg*, like
|
||||
* pgpipe, but in other cases we define rename to pgrename just on Win32.
|
||||
*/
|
||||
#ifndef WIN32
|
||||
/*
|
||||
* The function prototypes are not supplied because every C file
|
||||
* includes this file.
|
||||
*/
|
||||
#define pgpipe(a) pipe(a)
|
||||
#define piperead(a,b,c) read(a,b,c)
|
||||
#define pipewrite(a,b,c) write(a,b,c)
|
||||
#else
|
||||
extern int pgpipe(int handles[2]);
|
||||
extern int piperead(int s, char *buf, int len);
|
||||
|
||||
#define pipewrite(a,b,c) send(a,b,c,0)
|
||||
|
||||
#ifdef WIN32
|
||||
#define PG_SIGNAL_COUNT 32
|
||||
#define kill(pid,sig) pgkill(pid,sig)
|
||||
extern int pgkill(int pid, int sig);
|
||||
|
@ -496,7 +496,8 @@ pipe_read_line(char *cmd, char *line, int maxsize)
|
||||
/*
|
||||
* pclose() plus useful error reporting
|
||||
* Is this necessary? bjm 2004-05-11
|
||||
* It is better here because pipe.c has win32 backend linkage.
|
||||
* Originaally this was stated to be here because pipe.c had backend linkage.
|
||||
* Perhaps that's no longer so now we have got rid of pipe.c amd 2012-03-28
|
||||
*/
|
||||
int
|
||||
pclose_check(FILE *stream)
|
||||
|
@ -73,7 +73,6 @@ sub mkvcbuild
|
||||
$postgres->ReplaceFile('src\backend\port\pg_shmem.c','src\backend\port\win32_shmem.c');
|
||||
$postgres->ReplaceFile('src\backend\port\pg_latch.c','src\backend\port\win32_latch.c');
|
||||
$postgres->AddFiles('src\port',@pgportfiles);
|
||||
$postgres->AddFile('src\backend\port\pipe.c');
|
||||
$postgres->AddDir('src\timezone');
|
||||
$postgres->AddFiles('src\backend\parser','scan.l','gram.y');
|
||||
$postgres->AddFiles('src\backend\bootstrap','bootscanner.l','bootparse.y');
|
||||
|
Loading…
Reference in New Issue
Block a user