Remove uses of MSG_WAITALL temporarily, since it doesn't
authorTom Lane
Sun, 17 Jan 1999 03:10:23 +0000 (03:10 +0000)
committerTom Lane
Sun, 17 Jan 1999 03:10:23 +0000 (03:10 +0000)
seem to be portable (HPUX doesn't like it, anyway).  Also, clean up
StreamConnection(), which was mis-coded to assume that the address
family field is already set when it's called.

src/backend/libpq/pqcomm.c
src/backend/libpq/pqcomprim.c

index e7da8d89a8cd590397651e6b0e4f656a184eba96..c8de26e8d5b497ec5426bef774ce8a8d7fde69fc 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- *  $Id: pqcomm.c,v 1.61 1999/01/12 12:49:51 scrappy Exp $
+ *  $Id: pqcomm.c,v 1.62 1999/01/17 03:10:23 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -102,16 +102,11 @@ int
 pq_getchar(void)
 {
    char c;
-   char isDone = 0;
 
-   do {
-     if (recv(MyProcPort->sock,&c,1,MSG_WAITALL) != 1) {
+   while (recv(MyProcPort->sock, &c, 1, 0) != 1) {
        if (errno != EINTR)
-         return EOF; /* Not interrupted, so something went wrong */
-     }
-     else
-       isDone = 1;
-   } while (!isDone);
+           return EOF; /* Not interrupted, so something went wrong */
+   }
      
    return c;
 }
@@ -123,17 +118,12 @@ pq_getchar(void)
 int
 pq_peekchar(void) {
    char c;
-   char isDone = 0;
 
-   do {
-     if (recv(MyProcPort->sock,&c,1,MSG_WAITALL | MSG_PEEK) != 1) {
+   while (recv(MyProcPort->sock, &c, 1, MSG_PEEK) != 1) {
        if (errno != EINTR)
-         return EOF; /* Not interrupted, so something went wrong */
-     }
-     else
-       isDone = 1;
-   } while (!isDone);
-     
+           return EOF; /* Not interrupted, so something went wrong */
+   }
+
    return c;
 }
   
@@ -568,14 +558,10 @@ StreamServerPort(char *hostName, short portName, int *fdP)
 int
 StreamConnection(int server_fd, Port *port)
 {
-   int         len;
    SOCKET_SIZE_TYPE    addrlen;
-   int         family = port->raddr.sa.sa_family;
 
    /* accept connection (and fill in the client (remote) address) */
-   len = family == AF_INET ?
-       sizeof(struct sockaddr_in) : sizeof(struct sockaddr_un);
-   addrlen = len;
+   addrlen = sizeof(port->raddr);
    if ((port->sock = accept(server_fd,
                             (struct sockaddr *) & port->raddr,
                             &addrlen)) < 0)
@@ -585,14 +571,16 @@ StreamConnection(int server_fd, Port *port)
    }
 
    /* fill in the server (local) address */
-   addrlen = len;
+   addrlen = sizeof(port->laddr);
    if (getsockname(port->sock, (struct sockaddr *) & port->laddr,
                    &addrlen) < 0)
    {
        elog(ERROR, "postmaster: StreamConnection: getsockname: %m");
        return STATUS_ERROR;
    }
-   if (family == AF_INET)
+
+   /* select TCP_NODELAY option if it's a TCP connection */
+   if (port->laddr.sa.sa_family == AF_INET)
    {
        struct protoent *pe;
        int         on = 1;
index 8c08adb3fd4cde11f06a86e501a33a48ca0c8516..6d5897e747a0fef1169e8ccc3b26e32d200485be 100644 (file)
@@ -1,6 +1,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "postgres.h"
@@ -146,7 +147,7 @@ pqGetNBytes(char *s, size_t len)
    int bytesDone = 0;
 
    do {
-     int r = recv(MyProcPort->sock, s+bytesDone, len-bytesDone, MSG_WAITALL);
+     int r = recv(MyProcPort->sock, s+bytesDone, len-bytesDone, 0);
      if (r == 0 || r == -1) {
        if (errno != EINTR)
          return EOF; /* All other than signal-interrupted is error */