You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/04/25 23:25:25 UTC
[2/3] qpid-proton git commit: PROTON-1469: c libuv - read/write error
closes full transport
PROTON-1469: c libuv - read/write error closes full transport
read/write errors now only close the read/write half of the transport to allow
outstanding work to complete on the other half.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/cd5e695f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/cd5e695f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/cd5e695f
Branch: refs/heads/master
Commit: cd5e695f3604c0ef964eaad6462058e5d599765e
Parents: c8f9a2e
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Apr 25 16:35:10 2017 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Apr 25 19:25:02 2017 -0400
----------------------------------------------------------------------
proton-c/src/proactor/libuv.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/cd5e695f/proton-c/src/proactor/libuv.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/libuv.c b/proton-c/src/proactor/libuv.c
index 3631e8b..4992b40 100644
--- a/proton-c/src/proactor/libuv.c
+++ b/proton-c/src/proactor/libuv.c
@@ -424,23 +424,33 @@ static pconnection_t *get_pconnection(pn_connection_t* c) {
return (pconnection_t*) pn_record_get(r, PN_PROACTOR);
}
+/* Remember the first error code from a bad connect attempt.
+ * This is not yet a full-blown error as we might succeed connecting
+ * to a different address if there are several.
+ */
static inline void pconnection_bad_connect(pconnection_t *pc, int err) {
if (!pc->connected) {
pc->connected = err; /* Remember first connect error in case they all fail */
}
}
-static void pconnection_error(pconnection_t *pc, int err, const char* what) {
- assert(err);
- pconnection_bad_connect(pc, err);
+/* Set the error condition, but don't close the driver. */
+static void pconnection_set_error(pconnection_t *pc, int err, const char* what) {
pn_connection_driver_t *driver = &pc->driver;
- pn_connection_driver_bind(driver); /* Bind so errors will be reported */
+ pn_connection_driver_bind(driver); /* Make sure we are bound so errors will be reported */
if (!pn_condition_is_set(pn_transport_condition(driver->transport))) {
pn_connection_driver_errorf(driver, uv_err_name(err), "%s %s:%s: %s",
what, pc->addr.host, pc->addr.port,
uv_strerror(err));
}
- pn_connection_driver_close(driver);
+}
+
+/* Set the error condition and close the driver. */
+static void pconnection_error(pconnection_t *pc, int err, const char* what) {
+ assert(err);
+ pconnection_bad_connect(pc, err);
+ pconnection_set_error(pc, err, what);
+ pn_connection_driver_close(&pc->driver);
}
static void listener_error_lh(pn_listener_t *l, int err, const char* what) {
@@ -726,12 +736,13 @@ static void on_tick(uv_timer_t *timer) {
static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
pconnection_t *pc = (pconnection_t*)stream->data;
- if (nread >= 0) {
+ if (nread > 0) {
pn_connection_driver_read_done(&pc->driver, nread);
- } else if (nread == UV_EOF) { /* hangup */
+ } else if (nread < 0) {
+ if (nread != UV_EOF) { /* hangup */
+ pconnection_set_error(pc, nread, "on read from");
+ }
pn_connection_driver_read_close(&pc->driver);
- } else {
- pconnection_error(pc, nread, "on read from");
}
work_notify(&pc->work);
}
@@ -741,7 +752,8 @@ static void on_write(uv_write_t* write, int err) {
size_t size = pc->writing;
pc->writing = 0;
if (err) {
- pconnection_error(pc, err, "on write to");
+ pconnection_set_error(pc, err, "on write to");
+ pn_connection_driver_write_close(&pc->driver);
} else if (!pn_connection_driver_write_closed(&pc->driver)) {
pn_connection_driver_write_done(&pc->driver, size);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org