*** a/src/backend/libpq/pqcomm.c
--- b/src/backend/libpq/pqcomm.c
***************
*** 240,249 **** StreamDoUnlink(int code, Datum arg)
  int
  StreamServerPort(int family, char *hostName, unsigned short portNumber,
  				 char *unixSocketName,
! 				 int ListenSocket[], int MaxListen)
  {
! 	int			fd,
! 				err;
  	int			maxconn;
  	int			ret;
  	char		portNumberStr[32];
--- 240,249 ----
  int
  StreamServerPort(int family, char *hostName, unsigned short portNumber,
  				 char *unixSocketName,
! 				 pgsocket ListenSocket[], int MaxListen)
  {
! 	pgsocket	fd;
! 	int			err;
  	int			maxconn;
  	int			ret;
  	char		portNumberStr[32];
***************
*** 570,576 **** Setup_AF_UNIX(void)
   * RETURNS: STATUS_OK or STATUS_ERROR
   */
  int
! StreamConnection(int server_fd, Port *port)
  {
  	/* accept connection and fill in the client (remote) address */
  	port->raddr.salen = sizeof(port->raddr.addr);
--- 570,576 ----
   * RETURNS: STATUS_OK or STATUS_ERROR
   */
  int
! StreamConnection(pgsocket server_fd, Port *port)
  {
  	/* accept connection and fill in the client (remote) address */
  	port->raddr.salen = sizeof(port->raddr.addr);
***************
*** 676,682 **** StreamConnection(int server_fd, Port *port)
   * we do NOT want to send anything to the far end.
   */
  void
! StreamClose(int sock)
  {
  	closesocket(sock);
  }
--- 676,682 ----
   * we do NOT want to send anything to the far end.
   */
  void
! StreamClose(pgsocket sock)
  {
  	closesocket(sock);
  }
*** a/src/backend/postmaster/pgstat.c
--- b/src/backend/postmaster/pgstat.c
***************
*** 130,136 **** PgStat_MsgBgWriter BgWriterStats;
   * Local data
   * ----------
   */
! NON_EXEC_STATIC int pgStatSock = -1;
  
  static struct sockaddr_storage pgStatAddr;
  
--- 130,136 ----
   * Local data
   * ----------
   */
! NON_EXEC_STATIC pgsocket pgStatSock = -1;
  
  static struct sockaddr_storage pgStatAddr;
  
*** a/src/backend/postmaster/postmaster.c
--- b/src/backend/postmaster/postmaster.c
***************
*** 172,178 **** int			ReservedBackends;
  
  /* The socket(s) we're listening to. */
  #define MAXLISTEN	64
! static int	ListenSocket[MAXLISTEN];
  
  /*
   * Set by the -o option
--- 172,178 ----
  
  /* The socket(s) we're listening to. */
  #define MAXLISTEN	64
! static pgsocket ListenSocket[MAXLISTEN];
  
  /*
   * Set by the -o option
***************
*** 4408,4414 **** extern slock_t *ProcStructLock;
  extern PROC_HDR *ProcGlobal;
  extern PGPROC *AuxiliaryProcs;
  extern PMSignalData *PMSignalState;
! extern int	pgStatSock;
  
  #ifndef WIN32
  #define write_inheritable_socket(dest, src, childpid) ((*(dest) = (src)), true)
--- 4408,4414 ----
  extern PROC_HDR *ProcGlobal;
  extern PGPROC *AuxiliaryProcs;
  extern PMSignalData *PMSignalState;
! extern pgsocket pgStatSock;
  
  #ifndef WIN32
  #define write_inheritable_socket(dest, src, childpid) ((*(dest) = (src)), true)
*** a/src/include/libpq/libpq-be.h
--- b/src/include/libpq/libpq-be.h
***************
*** 103,109 **** typedef struct
  
  typedef struct Port
  {
! 	int			sock;			/* File descriptor */
  	ProtocolVersion proto;		/* FE/BE protocol version */
  	SockAddr	laddr;			/* local addr (postmaster) */
  	SockAddr	raddr;			/* remote addr (client) */
--- 103,109 ----
  
  typedef struct Port
  {
! 	pgsocket	sock;			/* File descriptor */
  	ProtocolVersion proto;		/* FE/BE protocol version */
  	SockAddr	laddr;			/* local addr (postmaster) */
  	SockAddr	raddr;			/* remote addr (client) */
*** a/src/include/libpq/libpq.h
--- b/src/include/libpq/libpq.h
***************
*** 45,54 **** typedef struct
   * prototypes for functions in pqcomm.c
   */
  extern int StreamServerPort(int family, char *hostName,
! 		 unsigned short portNumber, char *unixSocketName, int ListenSocket[],
  				 int MaxListen);
! extern int	StreamConnection(int server_fd, Port *port);
! extern void StreamClose(int sock);
  extern void TouchSocketFile(void);
  extern void pq_init(void);
  extern void pq_comm_reset(void);
--- 45,54 ----
   * prototypes for functions in pqcomm.c
   */
  extern int StreamServerPort(int family, char *hostName,
! 		 unsigned short portNumber, char *unixSocketName, pgsocket ListenSocket[],
  				 int MaxListen);
! extern int	StreamConnection(pgsocket server_fd, Port *port);
! extern void StreamClose(pgsocket sock);
  extern void TouchSocketFile(void);
  extern void pq_init(void);
  extern void pq_comm_reset(void);
*** a/src/include/port.h
--- b/src/include/port.h
***************
*** 17,25 ****
  #include <netdb.h>
  #include <pwd.h>
  
  /* non-blocking */
! extern bool pg_set_noblock(int sock);
! extern bool pg_set_block(int sock);
  
  /* Portable path handling for Unix/Win32 (in path.c) */
  
--- 17,32 ----
  #include <netdb.h>
  #include <pwd.h>
  
+ /* socket has a different definition on WIN32 */
+ #ifndef WIN32
+ typedef char pgsocket;
+ #else
+ typedef SOCKET pgsocket;
+ #endif
+ 
  /* non-blocking */
! extern bool pg_set_noblock(pgsocket sock);
! extern bool pg_set_block(pgsocket sock);
  
  /* Portable path handling for Unix/Win32 (in path.c) */
  
*** a/src/port/noblock.c
--- b/src/port/noblock.c
***************
*** 18,24 ****
  
  
  bool
! pg_set_noblock(int sock)
  {
  #if !defined(WIN32)
  	return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
--- 18,24 ----
  
  
  bool
! pg_set_noblock(pgsocket sock)
  {
  #if !defined(WIN32)
  	return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
***************
*** 32,38 **** pg_set_noblock(int sock)
  
  
  bool
! pg_set_block(int sock)
  {
  #if !defined(WIN32)
  	int			flags;
--- 32,38 ----
  
  
  bool
! pg_set_block(pgsocket sock)
  {
  #if !defined(WIN32)
  	int			flags;