*
*
* 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
#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>
#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
FILE *Pfout,
*Pfin;
FILE *Pfdebug; /* debugging libpq */
-int PQAsyncNotifyWaiting; /* for async. notification */
/* --------------------------------
* pq_init - open portal file descriptors
elog(FATAL, "pq_init: Couldn't initialize socket connection");
PQnotifies_init();
if (getenv("LIBPQ_DEBUG"))
- {
Pfdebug = stderr;
- }
else
- {
Pfdebug = NULL;
- }
}
/* -------------------------
fclose(Pfout);
Pfout = NULL;
}
- PQAsyncNotifyWaiting = 0;
PQnotifies_init();
- pq_unregoob();
}
/* --------------------------------
{
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"); */
*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
return (EOF);
if (fgets(s, maxlen - 1, Pfin) == NULL)
- {
return feof(Pfin) ? EOF : 1;
- }
else
{
for (; *s; s++)
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);
}
}
-/* ---
- * 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
* --------------------------------
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
*
void
StreamDoUnlink()
{
- if (sock_path[0])
- unlink(sock_path);
+ Assert(sock_path[0]);
+ unlink(sock_path);
}
int
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)
{
return (STATUS_ERROR);
}
+ if (family == AF_UNIX)
+ on_proc_exit(StreamDoUnlink, NULL);
+
listen(fd, SOMAXCONN);
/*
*fdP = fd;
if (family == AF_UNIX)
- {
chmod(sock_path, 0777);
- }
return (STATUS_OK);
}
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