chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / symsocket.c
index 25657db7c8a4bc2fd39b4dcc7a68db3c363bcabe..22f0bf675fcc31333e76c13fb81ee9fc86ba1a8e 100644 (file)
@@ -11,6 +11,18 @@ static char rcsid[] =
 
 /*
  * $Log$
+ * Revision 1.6  2008/02/27 00:27:22  james
+ * *** empty log message ***
+ *
+ * Revision 1.5  2008/02/20 22:54:22  staffcvs
+ * *** empty log message ***
+ *
+ * Revision 1.4  2008/02/20 18:31:53  james
+ * *** empty log message ***
+ *
+ * Revision 1.3  2008/02/14 02:46:44  james
+ * *** empty log message ***
+ *
  * Revision 1.2  2008/02/14 00:57:58  james
  * *** empty log message ***
  *
@@ -23,9 +35,41 @@ static char rcsid[] =
 #include <sys/socket.h>
 #include <sys/un.h>
 
-#define BUF_SIZE 16384
+#define BUF_SIZE 65536
 #define MAX_TXN 4096
 
+int
+wrap_recv (int fd, void *buf, int len)
+{
+  int red;
+
+  red = recv (fd, buf, len, 0);
+  if (!red)
+    return -1;
+
+  if ((red < 0) && (errno == EAGAIN))
+    red = 0;
+
+  return red;
+}
+
+int
+wrap_send (int fd, void *buf, int len)
+{
+  int writ;
+
+  errno = 0;
+
+  writ = send (fd, buf, len, MSG_NOSIGNAL);
+
+  if (!writ)
+    return -1;
+
+  if ((writ < 0) && (errno == EAGAIN))
+    writ = 0;
+
+  return writ;
+}
 
 void
 socket_free (Socket * s)
@@ -36,7 +80,29 @@ socket_free (Socket * s)
     slide_free (s->read_buf);
   if (s->write_buf)
     slide_free (s->write_buf);
+  if (s->path_to_unlink)
+    {
+      unlink (s->path_to_unlink);
+      free (s->path_to_unlink);
+    }
   close (s->fd);
+  free (s);
+}
+
+void
+socket_free_parent (Socket * s)
+{
+  if (!s)
+    return;
+  if (s->read_buf)
+    slide_free (s->read_buf);
+  if (s->write_buf)
+    slide_free (s->write_buf);
+  if (s->path_to_unlink)
+    free (s->path_to_unlink);
+  close (s->fd);
+
+  free (s);
 }
 
 
@@ -86,6 +152,7 @@ socket_listen (char *path)
   ret->write_buf = NULL;
 
   ret->fd = fd;
+  ret->path_to_unlink = strdup (path);
 
 
   return ret;
@@ -164,6 +231,7 @@ socket_connect (char *path)
 
   return ret;
 }
+
 void
 socket_consume_msg (Socket * s)
 {
@@ -172,7 +240,7 @@ socket_consume_msg (Socket * s)
   if (!s->msg)
     return;
 
-  ipc_consume_message_in_slide(s->read_buf);
+  ipc_consume_message_in_slide (s->read_buf);
   s->msg = ipc_check_for_message_in_slide (s->read_buf);
 
 }
@@ -203,7 +271,7 @@ socket_post_select (Socket * s, fd_set * rfds, fd_set * wfds)
 {
   char buf[1024];
   int n;
-  int error=0;
+  int error = 0;
 
 
   if ((!SLIDE_EMPTY (s->write_buf)) && FD_ISSET (s->fd, wfds))
@@ -211,10 +279,11 @@ socket_post_select (Socket * s, fd_set * rfds, fd_set * wfds)
       n =
         (SLIDE_BYTES (s->write_buf) >
          MAX_TXN) ? MAX_TXN : SLIDE_BYTES (s->write_buf);
-      n = wrap_write (s->fd, SLIDE_RPTR (s->write_buf), n);
+      n = wrap_send (s->fd, SLIDE_RPTR (s->write_buf), n);
       if (n > 0)
         slide_consume (s->write_buf, n);
-     if (n<0) error=-1;
+      if (n < 0)
+        error = -1;
     }
 
   if (!SLIDE_FULL (s->read_buf) && FD_ISSET (s->fd, rfds))
@@ -222,10 +291,11 @@ socket_post_select (Socket * s, fd_set * rfds, fd_set * wfds)
       n =
         (SLIDE_SPACE (s->read_buf) >
          MAX_TXN) ? MAX_TXN : SLIDE_SPACE (s->read_buf);
-      n = wrap_read (s->fd, SLIDE_WPTR (s->read_buf), n);
+      n = wrap_recv (s->fd, SLIDE_WPTR (s->read_buf), n);
       if (n > 0)
         slide_added (s->read_buf, n);
-     if (n<0) error=-1;
+      if (n < 0)
+        error = -1;
     }
 
   s->msg = ipc_check_for_message_in_slide (s->read_buf);
@@ -247,15 +317,16 @@ socket_write (Socket * s, void *buf, int len)
   n =
     (SLIDE_BYTES (s->write_buf) >
      MAX_TXN) ? MAX_TXN : SLIDE_BYTES (s->write_buf);
-  n = wrap_write (s->fd, SLIDE_RPTR (s->write_buf), n);
-   {
-       uint8_t *c=SLIDE_RPTR(s->write_buf);
+  n = wrap_send (s->fd, SLIDE_RPTR (s->write_buf), n);
+  {
+    uint8_t *c = SLIDE_RPTR (s->write_buf);
   }
 
   if (n > 0)
     slide_consume (s->write_buf, n);
-  
-  if (n<0) return -1;
+
+  if (n < 0)
+    return -1;
 
   return len;
 }