qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tr...@apache.org
Subject svn commit: r1393074 - /qpid/proton/trunk/proton-c/src/driver.c
Date Tue, 02 Oct 2012 18:13:59 GMT
Author: tross
Date: Tue Oct  2 18:13:59 2012
New Revision: 1393074

URL: http://svn.apache.org/viewvc?rev=1393074&view=rev
Log:
NO-JIRA - Set FDs to O_NONBLOCK in the driver, including handling of EAGAIN return codes.

Modified:
    qpid/proton/trunk/proton-c/src/driver.c

Modified: qpid/proton/trunk/proton-c/src/driver.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/driver.c?rev=1393074&r1=1393073&r2=1393074&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/driver.c (original)
+++ qpid/proton/trunk/proton-c/src/driver.c Tue Oct  2 18:13:59 2012
@@ -29,6 +29,7 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #include <proton/driver.h>
 #include <proton/error.h>
@@ -217,6 +218,13 @@ static void pn_configure_sock(int sock) 
     perror("setsockopt");
   };
   */
+
+    int flags = fcntl(sock, F_GETFL);
+    flags |= O_NONBLOCK;
+
+    if (fcntl(sock, F_SETFL, flags) < 0) {
+        perror("fcntl");
+    }
 }
 
 pn_connector_t *pn_listener_accept(pn_listener_t *l)
@@ -310,14 +318,13 @@ pn_connector_t *pn_connector(pn_driver_t
     return NULL;
   }
 
-  pn_configure_sock(sock);
-
   if (connect(sock, addr->ai_addr, addr->ai_addrlen) == -1) {
     pn_error_from_errno(driver->error, "connect");
     freeaddrinfo(addr);
     return NULL;
   }
 
+  pn_configure_sock(sock);
   freeaddrinfo(addr);
 
   pn_connector_t *c = pn_connector_fd(driver, sock, context);
@@ -457,8 +464,13 @@ void pn_connector_free(pn_connector_t *c
 static void pn_connector_read(pn_connector_t *ctor)
 {
   ssize_t n = recv(ctor->fd, ctor->input + ctor->input_size, IO_BUF_SIZE - ctor->input_size,
0);
-  if (n <= 0) {
-    if (n < 0) perror("read");
+  if (n < 0) {
+      if (errno != EAGAIN) {
+          if (n < 0) perror("read");
+          ctor->status &= ~PN_SEL_RD;
+          ctor->input_eos = true;
+      }
+  } else if (n == 0) {
     ctor->status &= ~PN_SEL_RD;
     ctor->input_eos = true;
   } else {
@@ -522,9 +534,11 @@ static void pn_connector_write(pn_connec
     ssize_t n = send(ctor->fd, ctor->output, ctor->output_size, MSG_NOSIGNAL);
     if (n < 0) {
       // XXX
-      perror("send");
-      ctor->output_size = 0;
-      ctor->output_done = true;
+        if (errno != EAGAIN) {
+            perror("send");
+            ctor->output_size = 0;
+            ctor->output_done = true;
+        }
     } else {
       ctor->output_size -= n;
       memmove(ctor->output, ctor->output + n, ctor->output_size);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message