event: reduce copy-paste
This commit is contained in:
36
src/event.c
36
src/event.c
@@ -110,30 +110,17 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
|
|||||||
|
|
||||||
if (conn->tls) {
|
if (conn->tls) {
|
||||||
ret = tls_write(conn->tls, &sq->data[sq->written], towrite);
|
ret = tls_write(conn->tls, &sq->data[sq->written], towrite);
|
||||||
|
if (ret < 0 && !tls_is_recoverable(tls_error(conn->tls)))
|
||||||
if (ret < 0 && !tls_is_recoverable(tls_error(conn->tls))) {
|
|
||||||
/* an error occurred */
|
|
||||||
conn->error = 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 {
|
} else {
|
||||||
ret = sock_write(conn->sock, &sq->data[sq->written], towrite);
|
ret = sock_write(conn->sock, &sq->data[sq->written], towrite);
|
||||||
|
if (ret < 0 && !sock_is_recoverable(sock_error()))
|
||||||
if (ret < 0 && !sock_is_recoverable(sock_error())) {
|
|
||||||
/* an error occurred */
|
|
||||||
conn->error = 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 */
|
/* all data for this queue item written, delete and move on */
|
||||||
xmpp_free(ctx, sq->data);
|
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
|
/* fire any ready timed handlers, then make sure we don't wait past
|
||||||
make sure we don't wait past the time when timed handlers need
|
the time when timed handlers need to be called */
|
||||||
to be called */
|
|
||||||
next = handler_fire_timed(ctx);
|
next = handler_fire_timed(ctx);
|
||||||
|
|
||||||
usec = ((next < timeout) ? next : timeout) * 1000;
|
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. */
|
/* Check if there is something in the SSL buffer. */
|
||||||
if (conn->tls) {
|
if (conn->tls)
|
||||||
tls_read_bytes += tls_pending(conn->tls);
|
tls_read_bytes += tls_pending(conn->tls);
|
||||||
}
|
|
||||||
|
|
||||||
if (conn->state != XMPP_STATE_DISCONNECTED && conn->sock > max)
|
if (conn->state != XMPP_STATE_DISCONNECTED && conn->sock > max)
|
||||||
max = conn->sock;
|
max = conn->sock;
|
||||||
@@ -282,8 +267,7 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (conn->tls) {
|
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));
|
xmpp_debug(ctx, "xmpp", "Unrecoverable TLS error, %d.", tls_error(conn->tls));
|
||||||
conn->error = tls_error(conn->tls);
|
conn->error = tls_error(conn->tls);
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
|
|||||||
Reference in New Issue
Block a user