[uim-commit] r564 - trunk/uim

ekato at freedesktop.org ekato at freedesktop.org
Sat Feb 5 21:00:38 PST 2005


Author: ekato
Date: 2005-02-05 21:00:35 -0800 (Sat, 05 Feb 2005)
New Revision: 564

Modified:
   trunk/uim/uim-helper-server.c
   trunk/uim/uim-helper.c
Log:
* uim/uim-helper-server.c (parse_content) : Retry sending message
  if write(2) fails with EAGAIN and EINTR.  If return value of
  write(2) is less than requested length, retry with remaining
  buffer.
* uim/uim-helper.c (uim_helper_send_message) : Ditto.


Modified: trunk/uim/uim-helper-server.c
===================================================================
--- trunk/uim/uim-helper-server.c	2005-02-06 04:45:39 UTC (rev 563)
+++ trunk/uim/uim-helper-server.c	2005-02-06 05:00:35 UTC (rev 564)
@@ -128,16 +128,32 @@
 parse_content(char *content, struct client *cl)
 {
   int i;
-  int ret;
+  int ret, content_len, out_len;
+  char *out;
 
+  content_len = strlen(content);
+
   for (i = 0; i < nr_client_slots; i++) {
     if (clients[i].fd != -1 && clients[i].fd != cl->fd &&
 		    (uim_helper_fd_writable(clients[i].fd) > 0)) {
-      ret = write(clients[i].fd, content, strlen(content));
+      out = content;
+      out_len = content_len;
+      while (out_len > 0) {
+	if ((ret = write(clients[i].fd, out, out_len)) < 0) {
+	  if (errno == EAGAIN || errno == EINTR)
+	    continue;
 
-      if (ret == -1 && errno == EPIPE) {
-	close(clients[i].fd);
-	free_client(&clients[i]);
+      	  if (errno == EPIPE) {
+	    close(clients[i].fd);
+	    free_client(&clients[i]);
+	  }
+	  break;
+        }
+	if (ret == 0)
+	  break;
+
+	out += ret;
+	out_len -= ret;
       }
     }
   }

Modified: trunk/uim/uim-helper.c
===================================================================
--- trunk/uim/uim-helper.c	2005-02-06 04:45:39 UTC (rev 563)
+++ trunk/uim/uim-helper.c	2005-02-06 05:00:35 UTC (rev 564)
@@ -81,6 +81,7 @@
 uim_helper_send_message(int fd, const char *message)
 {
   int res;
+  int out_len;
 
   if (fd < 0)
     return;
@@ -95,10 +96,22 @@
     int len = strlen(message);
     char *buf = malloc(len + 2);
     snprintf(buf, len + 2,"%s\n", message);
-    res = write(fd, buf, len + 1);
+
+    out_len = len + 1;
+    while (out_len > 0) {
+      if ((res = write(fd, buf, out_len) < 0)) {
+	if (errno == EAGAIN || errno == EINTR)
+	  continue;
+	break;
+      }
+      if (res == 0)
+	break;
+
+      buf += res;
+      out_len -= res;
+    }
     free(buf);
   }
-
   return;
 }
 



More information about the Uim-commit mailing list