diff --git a/src/event.c b/src/event.c index c7fd886..ede7932 100644 --- a/src/event.c +++ b/src/event.c @@ -110,30 +110,17 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout) if (conn->tls) { ret = tls_write(conn->tls, &sq->data[sq->written], towrite); - - if (ret < 0 && !tls_is_recoverable(tls_error(conn->tls))) { - /* an error occurred */ + if (ret < 0 && !tls_is_recoverable(tls_error(conn->tls))) conn->error = tls_error(conn->tls); - break; - } else if (ret < towrite) { - /* not all data could be sent now */ - if (ret >= 0) sq->written += ret; - break; - } - } else { ret = sock_write(conn->sock, &sq->data[sq->written], towrite); - - if (ret < 0 && !sock_is_recoverable(sock_error())) { - /* an error occurred */ + if (ret < 0 && !sock_is_recoverable(sock_error())) conn->error = sock_error(); - break; - } else if (ret < towrite) { - /* not all data could be sent now */ - if (ret >= 0) sq->written += ret; - break; - } } + if (ret > 0 && ret < towrite) + sq->written += ret; /* not all data could be sent now */ + if (ret != towrite) + break; /* partial write or an error */ /* all data for this queue item written, delete and move on */ xmpp_free(ctx, sq->data); @@ -167,9 +154,8 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout) } - /* fire any ready timed handlers, then - make sure we don't wait past the time when timed handlers need - to be called */ + /* fire any ready timed handlers, then make sure we don't wait past + the time when timed handlers need to be called */ next = handler_fire_timed(ctx); usec = ((next < timeout) ? next : timeout) * 1000; @@ -209,9 +195,8 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout) } /* Check if there is something in the SSL buffer. */ - if (conn->tls) { + if (conn->tls) tls_read_bytes += tls_pending(conn->tls); - } if (conn->state != XMPP_STATE_DISCONNECTED && conn->sock > max) max = conn->sock; @@ -282,8 +267,7 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout) } } else { if (conn->tls) { - if (!tls_is_recoverable(tls_error(conn->tls))) - { + if (!tls_is_recoverable(tls_error(conn->tls))) { xmpp_debug(ctx, "xmpp", "Unrecoverable TLS error, %d.", tls_error(conn->tls)); conn->error = tls_error(conn->tls); conn_disconnect(conn);