]> granicus.if.org Git - postgresql/blobdiff - src/backend/libpq/pqcomm.c
From: t-ishii@sra.co.jp
[postgresql] / src / backend / libpq / pqcomm.c
index 7dca3d567e581bc9aa7a6fef043254ab06a498f9..56f0fd658e99a40969c90891c09e56c3fda7f14c 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.42 1998/05/27 18:32:01 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.50 1998/07/26 04:30:28 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
  *             pq_putstr               - send a null terminated string to connection
  *             pq_putnchar             - send n characters to connection
  *             pq_putint               - send an integer to connection
+ *             pq_putncharlen          - send n characters to connection
+ *                                       (also send an int header indicating
+ *                                        the length)
  *             pq_getinaddr    - initialize address from host and port number
  *             pq_getinserv    - initialize address from host and service name
  *             pq_connect              - create remote input / output connection
  *             pq_accept               - accept remote input / output connection
- *             pq_async_notify - receive notification from backend.
  *
  * NOTES
  *             These functions are used by both frontend applications and
@@ -49,7 +51,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/socket.h>
-#include <sys/un.h>
 #include <netdb.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
@@ -66,6 +67,9 @@
 #include "libpq/auth.h"
 #include "libpq/libpq.h"               /* where the declarations go */
 #include "storage/ipc.h"
+#ifdef MULTIBYTE
+#include "mb/pg_wchar.h"
+#endif
 
 /* ----------------
  *             declarations
@@ -74,7 +78,6 @@
 FILE      *Pfout,
                   *Pfin;
 FILE      *Pfdebug;                    /* debugging libpq */
-int                    PQAsyncNotifyWaiting;           /* for async. notification */
 
 /* --------------------------------
  *             pq_init - open portal file descriptors
@@ -89,13 +92,9 @@ pq_init(int fd)
                elog(FATAL, "pq_init: Couldn't initialize socket connection");
        PQnotifies_init();
        if (getenv("LIBPQ_DEBUG"))
-       {
                Pfdebug = stderr;
-       }
        else
-       {
                Pfdebug = NULL;
-       }
 }
 
 /* -------------------------
@@ -159,9 +158,7 @@ pq_close()
                fclose(Pfout);
                Pfout = NULL;
        }
-       PQAsyncNotifyWaiting = 0;
        PQnotifies_init();
-       pq_unregoob();
 }
 
 /* --------------------------------
@@ -184,6 +181,14 @@ pq_getstr(char *s, int maxlen)
 {
        int                     c = '\0';
 
+#ifdef MULTIBYTE
+       unsigned char *p, *ps;
+       int len;
+
+       ps = s;
+       len = maxlen;
+#endif
+
        if (Pfin == (FILE *) NULL)
        {
 /*             elog(DEBUG, "Input descriptor is null"); */
@@ -194,6 +199,13 @@ pq_getstr(char *s, int maxlen)
                *s++ = c;
        *s = '\0';
 
+#ifdef MULTIBYTE
+       p = pg_client_to_server(ps, len);
+       if (ps != p) {  /* actual conversion has been done? */
+         strcpy(ps, p);
+       }
+#endif
+       
        /* -----------------
         *         If EOF reached let caller know.
         *         (This will only happen if we hit EOF before the string
@@ -229,9 +241,7 @@ PQgetline(char *s, int maxlen)
                return (EOF);
 
        if (fgets(s, maxlen - 1, Pfin) == NULL)
-       {
                return feof(Pfin) ? EOF : 1;
-       }
        else
        {
                for (; *s; s++)
@@ -331,7 +341,14 @@ pq_getint(int b)
 void
 pq_putstr(char *s)
 {
+#ifdef MULTIBYTE
+        unsigned char *p;
+
+        p = pg_server_to_client(s, strlen(s));
+       if (pqPutString(p, Pfout))
+#else
        if (pqPutString(s, Pfout))
+#endif
        {
                sprintf(PQerrormsg,
                                "FATAL: pq_putstr: fputs() failed: errno=%d\n", errno);
@@ -397,29 +414,6 @@ pq_putint(int i, int b)
        }
 }
 
-/* ---
- *        pq_sendoob - send a string over the out-of-band channel
- *        pq_recvoob - receive a string over the oob channel
- *     NB: Fortunately, the out-of-band channel doesn't conflict with
- *             buffered I/O because it is separate from regular com. channel.
- * ---
- */
-int
-pq_sendoob(char *msg, int len)
-{
-       int                     fd = fileno(Pfout);
-
-       return send(fd, msg, len, MSG_OOB);
-}
-
-int
-pq_recvoob(char *msgPtr, int len)
-{
-       int                     fd = fileno(Pfout);
-
-       return recv(fd, msgPtr, len, MSG_OOB);
-}
-
 /* --------------------------------
  *             pq_getinaddr - initialize address from host and port number
  * --------------------------------
@@ -486,55 +480,6 @@ pq_getinserv(struct sockaddr_in * sin, char *host, char *serv)
        return (pq_getinaddr(sin, host, ntohs(ss->s_port)));
 }
 
-/*
- * register an out-of-band listener proc--at most one allowed.
- * This is used for receiving async. notification from the backend.
- */
-void
-pq_regoob(void (*fptr) ())
-{
-       int                     fd = fileno(Pfout);
-
-#if defined(hpux)
-       ioctl(fd, FIOSSAIOOWN, MyProcPid);
-#elif defined(sco)
-       ioctl(fd, SIOCSPGRP, MyProcPid);
-#else
-       fcntl(fd, F_SETOWN, MyProcPid);
-#endif                                                 /* hpux */
-       pqsignal(SIGURG, fptr);
-}
-
-void
-pq_unregoob()
-{
-       pqsignal(SIGURG, SIG_DFL);
-}
-
-
-void
-pq_async_notify()
-{
-       char            msg[20];
-
-       /* int len = sizeof(msg); */
-       int                     len = 20;
-
-       if (pq_recvoob(msg, len) >= 0)
-       {
-               /* debugging */
-               printf("received notification: %s\n", msg);
-               PQAsyncNotifyWaiting = 1;
-               /* PQappendNotify(msg+1); */
-       }
-       else
-       {
-               extern int      errno;
-
-               printf("SIGURG but no data: len = %d, err=%d\n", len, errno);
-       }
-}
-
 /*
  * Streams -- wrapper around Unix socket system calls
  *
@@ -564,8 +509,8 @@ static char sock_path[MAXPGPATH + 1] = "";
 void
 StreamDoUnlink()
 {
-       if (sock_path[0])
-               unlink(sock_path);
+       Assert(sock_path[0]);
+       unlink(sock_path);
 }
 
 int
@@ -599,7 +544,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
                pqdebug("%s", PQerrormsg);
                return (STATUS_ERROR);
        }
-       bzero(&saddr, sizeof(saddr));
+       MemSet((char *) &saddr, 0, sizeof(saddr));
        saddr.sa.sa_family = family;
        if (family == AF_UNIX)
        {
@@ -628,6 +573,9 @@ StreamServerPort(char *hostName, short portName, int *fdP)
                return (STATUS_ERROR);
        }
 
+       if (family == AF_UNIX)
+               on_proc_exit(StreamDoUnlink, NULL);
+
        listen(fd, SOMAXCONN);
 
        /*
@@ -640,9 +588,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
 
        *fdP = fd;
        if (family == AF_UNIX)
-       {
                chmod(sock_path, 0777);
-       }
        return (STATUS_OK);
 }
 
@@ -793,3 +739,17 @@ StreamOpen(char *hostName, short portName, Port *port)
 
        return (STATUS_OK);
 }
+
+#ifdef MULTIBYTE
+void
+pq_putncharlen(char *s, int n)
+{
+  unsigned char *p;
+  int len;
+
+  p = pg_server_to_client(s, n);
+  len = strlen(p);
+  pq_putint(len, sizeof(int));
+  pq_putnchar(p, len);
+}
+#endif