[uim-commit] r725 - trunk/uim

ekato at freedesktop.org ekato at freedesktop.org
Fri Feb 25 12:03:34 PST 2005


Author: ekato
Date: 2005-02-25 12:03:29 -0800 (Fri, 25 Feb 2005)
New Revision: 725

Modified:
   trunk/uim/uim-helper-server.c
   trunk/uim/uim-helper.c
Log:
* uim/uim-helper.c (uim_helper_send_message) : Change timeout
  value.
* uim/uim-helper-server.c : Use non-blocking io.
(init_serv_fd) : Use O_NONBLOCK for server fd.
(parse_content) : Use select when write(2) fails with EAGAIN or
  EINTR.
(uim_helper_server_process_connection) : Use O_NONBLOCK for client
  fd.


Modified: trunk/uim/uim-helper-server.c
===================================================================
--- trunk/uim/uim-helper-server.c	2005-02-25 19:07:29 UTC (rev 724)
+++ trunk/uim/uim-helper-server.c	2005-02-25 20:03:29 UTC (rev 725)
@@ -45,6 +45,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <signal.h>
+#include <fcntl.h>
 #include "uim.h"
 #include "uim-helper.h"
 
@@ -70,6 +71,7 @@
 {
   int foo;
   int fd;
+  int flag;
   struct sockaddr_un myhost;
   struct passwd *pw;
   char *logname;
@@ -99,6 +101,17 @@
       chown(path, pw->pw_uid, -1);
   }
 
+  if ((flag = fcntl(fd, F_GETFL)) == -1) {
+    close(fd);
+    return -1;
+  }
+
+  flag |= O_NONBLOCK;
+  if (fcntl(fd, F_SETFL, flag) == -1) {
+    close(fd);
+    return -1;
+  }
+
   foo = listen(fd, 5);
   if (foo == -1) {
     perror("failed in listen()");
@@ -152,7 +165,19 @@
       while (out_len > 0) {
 	if ((ret = write(clients[i].fd, out, out_len)) < 0) {
 	  if (errno == EAGAIN || errno == EINTR) {
-	    continue;
+	    fd_set fds;
+	    struct timeval tv;
+	    int rc;
+
+	    FD_ZERO(&fds);
+	    FD_SET(clients[i].fd, &fds);
+	    tv.tv_sec = 10;
+	    tv.tv_usec = 0;
+	    rc = select(clients[i].fd + 1, NULL, &fds, NULL, &tv);
+	    if (rc > 0 && FD_ISSET(clients[i].fd, &fds)) {
+	      continue;
+	    }
+	    fprintf(stderr, "uim-helper-server failed to write\n");
 	  }
 
       	  if (errno == EPIPE) {
@@ -230,6 +255,7 @@
       struct sockaddr_un clientsoc;
       socklen_t len = sizeof(clientsoc);
       int new_fd;
+      int flag;
       struct client *cl;
       new_fd = accept(serv_fd, (struct sockaddr *)&clientsoc, &len);
 
@@ -238,6 +264,17 @@
 	continue;
       }
 
+      if ((flag = fcntl(new_fd, F_GETFL)) == -1) {
+	close(new_fd);
+	continue;
+      }
+
+      flag |= O_NONBLOCK;
+      if (fcntl(new_fd, F_SETFL, flag) == -1) {
+	close(new_fd);
+	continue;
+      }
+
       cl = get_unused_client();
       if (!cl) {
 	close(new_fd);
@@ -261,6 +298,8 @@
 
 	  if (result < 0) {
 	    FD_CLR(clients[i].fd, &readfds);
+	    if (clients[i].fd == fd_biggest)
+	      fd_biggest--;
 	    close(clients[i].fd);
 	    free_client(&clients[i]);
 	  }

Modified: trunk/uim/uim-helper.c
===================================================================
--- trunk/uim/uim-helper.c	2005-02-25 19:07:29 UTC (rev 724)
+++ trunk/uim/uim-helper.c	2005-02-25 20:03:29 UTC (rev 725)
@@ -141,8 +141,8 @@
 
 	FD_ZERO(&fds);
 	FD_SET(fd, &fds);
-	tv.tv_sec = 0;
-	tv.tv_usec = 100000;
+	tv.tv_sec = 10;
+	tv.tv_usec = 0;
 	rc = select(fd + 1, NULL, &fds, NULL, &tv);
 	if (rc > 0 && FD_ISSET(fd, &fds)) {
 	  continue;



More information about the Uim-commit mailing list