On Wed, May 28, 2014 at 12:29:28PM -0400, Tom Lane wrote:
> Bruce Momjian <br...@momjian.us> writes:
> > I think this is caused because the variable is not defined as SOCKET. 
> > The attached patch fixes this.  This should prevent the warning.
> 
> Surely that's just going to move the errors somewhere else.  The call
> site still expects the argument to be int[].

Ah, yes, you are right.  This is a similar problem I had with libpq
where PQsocket() had to return an int.

Attached is an updated patch which follows my previous coding of
checking for PGINVALID_SOCKET, and if not equal, assigns the value to an
integer handle.  I would also like to rename variable 's' to
'listen_sock', but that is not in the patch, for clarity reasons.

Should this be held for 9.5?  I think it is only warning removal.  On
the other hand, portability is what we do during beta testing.

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +
diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c
new file mode 100644
index caedbb8..4efa8fb
*** a/src/bin/pg_dump/parallel.c
--- b/src/bin/pg_dump/parallel.c
*************** readMessageFromPipe(int fd)
*** 1320,1337 ****
  /*
   * 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.
   */
  static 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)
  	{
  		write_msg(modulename, "pgpipe: could not create socket: error code %d\n",
  				  WSAGetLastError());
--- 1320,1342 ----
  /*
   * 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.  "handles" have to be integers so we check for errors then
!  * cast to integers.
   */
  static int
  pgpipe(int handles[2])
  {
! 	pgsocket		s, tmp_sock;
  	struct sockaddr_in serv_addr;
  	int			len = sizeof(serv_addr);
  
+ 	/* We have to use the Unix socket definition here. */
  	handles[0] = handles[1] = INVALID_SOCKET;
  
! 	/*
! 	 * setup listen socket
! 	 */
! 	if ((s = socket(AF_INET, SOCK_STREAM, 0)) == PGINVALID_SOCKET)
  	{
  		write_msg(modulename, "pgpipe: could not create socket: error code %d\n",
  				  WSAGetLastError());
*************** pgpipe(int handles[2])
*** 1363,1375 ****
  		closesocket(s);
  		return -1;
  	}
! 	if ((handles[1] = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
  	{
  		write_msg(modulename, "pgpipe: could not create second socket: error code %d\n",
  				  WSAGetLastError());
  		closesocket(s);
  		return -1;
  	}
  
  	if (connect(handles[1], (SOCKADDR *) &serv_addr, len) == SOCKET_ERROR)
  	{
--- 1368,1385 ----
  		closesocket(s);
  		return -1;
  	}
! 
! 	/*
! 	 * setup pipe handles
! 	 */
! 	if ((tmp_sock = socket(AF_INET, SOCK_STREAM, 0)) == PGINVALID_SOCKET)
  	{
  		write_msg(modulename, "pgpipe: could not create second socket: error code %d\n",
  				  WSAGetLastError());
  		closesocket(s);
  		return -1;
  	}
+ 	handles[1] = (int) tmp_sock;
  
  	if (connect(handles[1], (SOCKADDR *) &serv_addr, len) == SOCKET_ERROR)
  	{
*************** pgpipe(int handles[2])
*** 1378,1384 ****
  		closesocket(s);
  		return -1;
  	}
! 	if ((handles[0] = accept(s, (SOCKADDR *) &serv_addr, &len)) == INVALID_SOCKET)
  	{
  		write_msg(modulename, "pgpipe: could not accept connection: error code %d\n",
  				  WSAGetLastError());
--- 1388,1394 ----
  		closesocket(s);
  		return -1;
  	}
! 	if ((tmp_sock = accept(s, (SOCKADDR *) &serv_addr, &len)) == PGINVALID_SOCKET)
  	{
  		write_msg(modulename, "pgpipe: could not accept connection: error code %d\n",
  				  WSAGetLastError());
*************** pgpipe(int handles[2])
*** 1387,1392 ****
--- 1397,1404 ----
  		closesocket(s);
  		return -1;
  	}
+ 	handles[0] = (int) tmp_sock;
+ 
  	closesocket(s);
  	return 0;
  }
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to