1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-14 08:21:07 +03:00

Add WIN32 pipe implementation that uses sockets.

Claudio Natoli
This commit is contained in:
Bruce Momjian
2004-01-09 04:58:09 +00:00
parent 0d2148a71e
commit ee7fbb1eaa
4 changed files with 77 additions and 7 deletions

55
src/port/pipe.c Normal file
View File

@ -0,0 +1,55 @@
/*-------------------------------------------------------------------------
*
* pipe.c
* pipe()
*
* Copyright (c) 1996-2003, 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
* $PostgreSQL: pgsql/src/port/pipe.c,v 1.1 2004/01/09 04:58:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
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)
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 ||
listen(s, 1) == SOCKET_ERROR ||
getsockname(s, (SOCKADDR *) & serv_addr, &len) == SOCKET_ERROR ||
(handles[1] = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
closesocket(s);
return -1;
}
if (connect(handles[1], (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR ||
(handles[0] = accept(s, (SOCKADDR *) & serv_addr, &len)) == INVALID_SOCKET)
{
closesocket(handles[1]);
handles[1] = INVALID_SOCKET;
closesocket(s);
return -1;
}
closesocket(s);
return 0;
}