New functions gw_res_int and gw_res_bool.
[egate.git] / util / gip.c
index 9604f34..8265d49 100644 (file)
@@ -2,7 +2,23 @@
  * Europagate, 1995
  *
  * $Log: gip.c,v $
- * Revision 1.1  1995/03/27 08:24:58  adam
+ * Revision 1.6  1995/05/02 15:26:52  adam
+ * EINTR obvserved on reads and writes.
+ *
+ * Revision 1.5  1995/05/01  16:27:28  adam
+ * Various improvements. Close-on-exec and close on failure on either
+ * read or write FIFO.
+ *
+ * Revision 1.4  1995/04/21  16:38:07  adam
+ * Added more debugging logs.
+ *
+ * Revision 1.3  1995/04/20  15:12:42  adam
+ * Minor hacks really.
+ *
+ * Revision 1.2  1995/03/27  12:52:18  adam
+ * A little more verbose in marc dump.
+ *
+ * Revision 1.1  1995/03/27  08:24:58  adam
  * New module gip: Gateway IPc module.
  * New module gw-db: Gateway hash-db module (user information table).
  *
@@ -16,6 +32,9 @@
 #include <fcntl.h>
 #include <sys/file.h>
 #include <sys/stat.h>
+#include <errno.h>
+
+#include <gw-log.h>
 
 #include <gip.h>
 
@@ -33,6 +52,8 @@ GIP gip_initialize (const char *name)
     strcpy (gip->name, name);
     gip->ret = mknod (gip->name, S_IFIFO|0666, 0);
     gip->errno = errno;
+    gip->rfd = gip->wfd = -1;
+    gw_log (GW_LOG_DEBUG, "gip", "Creating %s", gip->name);
     return gip;
 }
 
@@ -50,6 +71,11 @@ int gip_infileno (GIP gip)
     return gip->rfd;
 }
 
+int gip_outfileno (GIP gip)
+{
+    return gip->wfd;
+}
+
 int gip_errno (GIP gip)
 {
     return gip->errno;
@@ -60,12 +86,17 @@ int gip_read (GIP gip, char *buf, size_t count)
     int r, no = 0;
     while (no < count)
     {
-        r = read (gip->rfd, buf+no, count-no);
-       if (r == -1)
-       {
-           gip->errno = errno;
-           return -1;
-       }
+        while (1)
+        {
+            r = read (gip->rfd, buf+no, count-no);
+            if (r != -1)
+                break;
+            if (errno != EINTR)
+            {
+                gip->errno = errno;
+                return -1;
+            }
+        }
        no += r;
     }
     return 0;
@@ -76,11 +107,16 @@ int gip_write (GIP gip, const char *buf, size_t count)
     int r, no = 0;
     while (no < count)
     {
-        r = write (gip->wfd, buf+no, count-no);
-       if (r == -1)
-       {
-           gip->errno = errno;
-           return -1;
+        while (1)
+        {
+            r = write (gip->wfd, buf+no, count-no);
+            if (r != -1)
+                break;
+            if (errno != EINTR)
+            {
+                gip->errno = errno;
+                return -1;
+            }
        }
        no += r;
     }