You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2015/02/15 18:23:02 UTC

[1/3] qpid-proton git commit: check result of pn_connect and report error appropriately

Repository: qpid-proton
Updated Branches:
  refs/heads/master db3d6e5fd -> 4867d7511


check result of pn_connect and report error appropriately


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/9f51b1f1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/9f51b1f1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/9f51b1f1

Branch: refs/heads/master
Commit: 9f51b1f1ff5b77c96b8261df9d45c33e36d20085
Parents: db3d6e5
Author: Rafael Schloming <rh...@alum.mit.edu>
Authored: Sun Feb 15 11:17:11 2015 -0500
Committer: Rafael Schloming <rh...@alum.mit.edu>
Committed: Sun Feb 15 11:17:11 2015 -0500

----------------------------------------------------------------------
 proton-c/src/reactor/connection.c  | 10 +++++++++-
 proton-c/src/transport/transport.c | 16 ++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9f51b1f1/proton-c/src/reactor/connection.c
----------------------------------------------------------------------
diff --git a/proton-c/src/reactor/connection.c b/proton-c/src/reactor/connection.c
index da0eb22..dd6fe1c 100644
--- a/proton-c/src/reactor/connection.c
+++ b/proton-c/src/reactor/connection.c
@@ -125,8 +125,16 @@ void pni_handle_bound(pn_reactor_t *reactor, pn_event_t *event) {
     colon[0] = '\0';
   }
   pn_socket_t sock = pn_connect(pn_reactor_io(reactor), host, port);
-  pn_free(str);
   pn_transport_t *transport = pn_event_transport(event);
+  // invalid sockets are ignored by poll, so we need to do this manualy
+  if (sock == PN_INVALID_SOCKET) {
+    pn_condition_t *cond = pn_transport_condition(transport);
+    pn_condition_set_name(cond, "proton:connect");
+    pn_condition_set_description(cond, pn_error_text(pn_io_error(pn_reactor_io(reactor))));
+    pn_transport_close_tail(transport);
+    pn_transport_close_head(transport);
+  }
+  pn_free(str);
   pn_reactor_selectable_transport(reactor, sock, transport);
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9f51b1f1/proton-c/src/transport/transport.c
----------------------------------------------------------------------
diff --git a/proton-c/src/transport/transport.c b/proton-c/src/transport/transport.c
index c49044d..ba79f31 100644
--- a/proton-c/src/transport/transport.c
+++ b/proton-c/src/transport/transport.c
@@ -966,8 +966,20 @@ int pn_do_error(pn_transport_t *transport, const char *condition, const char *fm
     transport->close_sent = true;
   }
   transport->halt = true;
-  pn_condition_set_name(&transport->condition, condition);
-  pn_condition_set_description(&transport->condition, buf);
+  pn_condition_t *cond = &transport->condition;
+  if (!pn_condition_is_set(cond)) {
+    pn_condition_set_name(cond, condition);
+    pn_condition_set_description(cond, buf);
+  } else {
+    const char *first = pn_condition_get_description(cond);
+    if (first) {
+      char extended[2048];
+      snprintf(extended, 2048, "%s (%s)", first, buf);
+      pn_condition_set_description(cond, extended);
+    } else {
+      pn_condition_set_description(cond, buf);
+    }
+  }
   pn_collector_t *collector = pni_transport_collector(transport);
   pn_collector_put(collector, PN_OBJECT, transport, PN_TRANSPORT_ERROR);
   if (transport->trace & PN_TRACE_DRV) {


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


[2/3] qpid-proton git commit: report read and write errors through the transport

Posted by rh...@apache.org.
report read and write errors through the transport


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/01cb00cc
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/01cb00cc
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/01cb00cc

Branch: refs/heads/master
Commit: 01cb00cc9c358e634230fc9b8e14f6e509b3155f
Parents: 9f51b1f
Author: Rafael Schloming <rh...@alum.mit.edu>
Authored: Sun Feb 15 11:36:23 2015 -0500
Committer: Rafael Schloming <rh...@alum.mit.edu>
Committed: Sun Feb 15 11:36:53 2015 -0500

----------------------------------------------------------------------
 proton-c/src/posix/io.c           |  7 +++++--
 proton-c/src/reactor/connection.c | 14 +++++++++++---
 2 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/01cb00cc/proton-c/src/posix/io.c
----------------------------------------------------------------------
diff --git a/proton-c/src/posix/io.c b/proton-c/src/posix/io.c
index 2284f90..d6d0ccd 100644
--- a/proton-c/src/posix/io.c
+++ b/proton-c/src/posix/io.c
@@ -223,7 +223,8 @@ pn_socket_t pn_accept(pn_io_t *io, pn_socket_t socket, char *name, size_t size)
 #ifdef MSG_NOSIGNAL
 ssize_t pn_send(pn_io_t *io, pn_socket_t socket, const void *buf, size_t len) {
   ssize_t count = send(socket, buf, len, MSG_NOSIGNAL);
-  io->wouldblock = count < 0 && (errno == EAGAIN || errno == EWOULDBLOCK);
+  io->wouldblock = (errno == EAGAIN || errno == EWOULDBLOCK);
+  if (count < 0) { pn_i_error_from_errno(io->error, "send"); }
   return count;
 }
 
@@ -237,7 +238,8 @@ static inline int pn_create_socket(int af) {
 #elif defined(SO_NOSIGPIPE)
 ssize_t pn_send(pn_io_t *io, pn_socket_t socket, const void *buf, size_t size) {
   ssize_t count = send(socket, buf, size, 0);
-  io->wouldblock = count < 0 && (errno == EAGAIN || errno == EWOULDBLOCK);
+  io->wouldblock = (errno == EAGAIN || errno == EWOULDBLOCK);
+  if (count < 0) { pn_i_error_from_errno(io->error, "send"); }
   return count;
 }
 
@@ -266,6 +268,7 @@ ssize_t pn_recv(pn_io_t *io, pn_socket_t socket, void *buf, size_t size)
 {
   ssize_t count = recv(socket, buf, size, 0);
   io->wouldblock = count < 0 && (errno == EAGAIN || errno == EWOULDBLOCK);
+  if (count < 0) { pn_i_error_from_errno(io->error, "recv"); }
   return count;
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/01cb00cc/proton-c/src/reactor/connection.c
----------------------------------------------------------------------
diff --git a/proton-c/src/reactor/connection.c b/proton-c/src/reactor/connection.c
index dd6fe1c..3560fc5 100644
--- a/proton-c/src/reactor/connection.c
+++ b/proton-c/src/reactor/connection.c
@@ -129,7 +129,7 @@ void pni_handle_bound(pn_reactor_t *reactor, pn_event_t *event) {
   // invalid sockets are ignored by poll, so we need to do this manualy
   if (sock == PN_INVALID_SOCKET) {
     pn_condition_t *cond = pn_transport_condition(transport);
-    pn_condition_set_name(cond, "proton:connect");
+    pn_condition_set_name(cond, "proton:io");
     pn_condition_set_description(cond, pn_error_text(pn_io_error(pn_reactor_io(reactor))));
     pn_transport_close_tail(transport);
     pn_transport_close_head(transport);
@@ -155,7 +155,11 @@ static void pni_connection_readable(pn_selectable_t *sel)
                         pn_transport_tail(transport), capacity);
     if (n <= 0) {
       if (n == 0 || !pn_wouldblock(pn_reactor_io(reactor))) {
-        if (n < 0) perror("recv");
+        if (n < 0) {
+          pn_condition_t *cond = pn_transport_condition(transport);
+          pn_condition_set_name(cond, "proton:io");
+          pn_condition_set_description(cond, pn_error_text(pn_io_error(pn_reactor_io(reactor))));
+        }
         pn_transport_close_tail(transport);
       }
     } else {
@@ -182,7 +186,11 @@ static void pni_connection_writable(pn_selectable_t *sel)
                         pn_transport_head(transport), pending);
     if (n < 0) {
       if (!pn_wouldblock(pn_reactor_io(reactor))) {
-        perror("send");
+        pn_condition_t *cond = pn_transport_condition(transport);
+        if (!pn_condition_is_set(cond)) {
+          pn_condition_set_name(cond, "proton:io");
+          pn_condition_set_description(cond, pn_error_text(pn_io_error(pn_reactor_io(reactor))));
+        }
         pn_transport_close_head(transport);
       }
     } else {


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


[3/3] qpid-proton git commit: don't try to process input if an error condition has already been indicated

Posted by rh...@apache.org.
don't try to process input if an error condition has already been indicated


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4867d751
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4867d751
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4867d751

Branch: refs/heads/master
Commit: 4867d7511bba393b8e9f936f1994e6ed753039cd
Parents: 01cb00c
Author: Rafael Schloming <rh...@alum.mit.edu>
Authored: Sun Feb 15 12:22:48 2015 -0500
Committer: Rafael Schloming <rh...@alum.mit.edu>
Committed: Sun Feb 15 12:22:48 2015 -0500

----------------------------------------------------------------------
 proton-c/src/transport/transport.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4867d751/proton-c/src/transport/transport.c
----------------------------------------------------------------------
diff --git a/proton-c/src/transport/transport.c b/proton-c/src/transport/transport.c
index ba79f31..593dbca 100644
--- a/proton-c/src/transport/transport.c
+++ b/proton-c/src/transport/transport.c
@@ -954,8 +954,12 @@ int pn_do_error(pn_transport_t *transport, const char *condition, const char *fm
   va_list ap;
   va_start(ap, fmt);
   char buf[1024];
-  // XXX: result
-  vsnprintf(buf, 1024, fmt, ap);
+  if (fmt) {
+    // XXX: result
+    vsnprintf(buf, 1024, fmt, ap);
+  } else {
+    buf[0] = '\0';
+  }
   va_end(ap);
   if (!transport->close_sent) {
     if (!transport->open_sent) {
@@ -969,14 +973,16 @@ int pn_do_error(pn_transport_t *transport, const char *condition, const char *fm
   pn_condition_t *cond = &transport->condition;
   if (!pn_condition_is_set(cond)) {
     pn_condition_set_name(cond, condition);
-    pn_condition_set_description(cond, buf);
+    if (fmt) {
+      pn_condition_set_description(cond, buf);
+    }
   } else {
     const char *first = pn_condition_get_description(cond);
-    if (first) {
+    if (first && fmt) {
       char extended[2048];
       snprintf(extended, 2048, "%s (%s)", first, buf);
       pn_condition_set_description(cond, extended);
-    } else {
+    } else if (fmt) {
       pn_condition_set_description(cond, buf);
     }
   }
@@ -1555,6 +1561,18 @@ ssize_t pn_transport_input(pn_transport_t *transport, const char *bytes, size_t
 // process pending input until none remaining or EOS
 static ssize_t transport_consume(pn_transport_t *transport)
 {
+  // This allows whatever is driving the I/O to set the error
+  // condition on the transport before doing pn_transport_close_head()
+  // or pn_transport_close_tail(). This allows all transport errors to
+  // flow to the app the same way, but provides cleaner error messages
+  // since we don't try to look for a protocol header when, e.g. the
+  // connection was refused.
+  if (!transport->bytes_input && transport->tail_closed &&
+      pn_condition_is_set(&transport->condition)) {
+    pn_do_error(transport, NULL, NULL);
+    return PN_EOS;
+  }
+
   size_t consumed = 0;
 
   while (transport->input_pending || transport->tail_closed) {


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