Bug fix: when using tls, if a stanza is bigger than the buffer of 4096 in event.c, the stanza will not be read as select will return 0 on the ssl socket and the data will be in ssl buffers. Partial fix, only for Linux for now

This commit is contained in:
Vlad-Mihai Sima
2012-01-01 20:09:18 +01:00
parent bdd70fcfaf
commit 511606835d
5 changed files with 25 additions and 3 deletions

View File

@@ -85,6 +85,7 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
char buf[4096]; char buf[4096];
uint64_t next; uint64_t next;
long usec; long usec;
int tls_read_bytes = 0;
if (ctx->loop_status == XMPP_LOOP_QUIT) return; if (ctx->loop_status == XMPP_LOOP_QUIT) return;
ctx->loop_status = XMPP_LOOP_RUNNING; ctx->loop_status = XMPP_LOOP_RUNNING;
@@ -215,6 +216,11 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
break; break;
} }
/* Check if there is something in the SSL buffer. */
if (conn->tls) {
tls_read_bytes += tls_pending(conn->tls);
}
if (conn->sock > max) max = conn->sock; if (conn->sock > max) max = conn->sock;
connitem = connitem->next; connitem = connitem->next;
@@ -232,7 +238,7 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
} }
/* no events happened */ /* no events happened */
if (ret == 0) return; if (ret == 0 && tls_read_bytes == 0) return;
/* process events */ /* process events */
connitem = ctx->connlist; connitem = ctx->connlist;
@@ -262,7 +268,7 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
break; break;
case XMPP_STATE_CONNECTED: case XMPP_STATE_CONNECTED:
if (FD_ISSET(conn->sock, &rfds)) { if (FD_ISSET(conn->sock, &rfds) || (conn->tls && tls_pending(conn->tls))) {
if (conn->tls) { if (conn->tls) {
ret = tls_read(conn->tls, buf, 4096); ret = tls_read(conn->tls, buf, 4096);
} else { } else {

View File

@@ -37,6 +37,7 @@ int tls_stop(tls_t *tls);
int tls_error(tls_t *tls); int tls_error(tls_t *tls);
int tls_pending(tls_t *tls);
int tls_read(tls_t *tls, void * const buff, const size_t len); int tls_read(tls_t *tls, void * const buff, const size_t len);
int tls_write(tls_t *tls, const void * const buff, const size_t len); int tls_write(tls_t *tls, const void * const buff, const size_t len);

View File

@@ -68,6 +68,11 @@ int tls_error(tls_t *tls)
return 0; return 0;
} }
int tls_pending(tls_t *tls)
{
return 0;
}
int tls_read(tls_t *tls, void * const buff, const size_t len) int tls_read(tls_t *tls, void * const buff, const size_t len)
{ {
return -1; return -1;

View File

@@ -107,6 +107,11 @@ int tls_error(tls_t *tls)
return 0; return 0;
} }
int tls_pending(tls_t *tls)
{
return gnutls_record_check_pending (tls->session);
}
int tls_read(tls_t *tls, void * const buff, const size_t len) int tls_read(tls_t *tls, void * const buff, const size_t len)
{ {
int ret; int ret;

View File

@@ -152,6 +152,11 @@ int tls_is_recoverable(int error)
|| error == SSL_ERROR_WANT_ACCEPT); || error == SSL_ERROR_WANT_ACCEPT);
} }
int tls_pending(tls_t *tls)
{
return SSL_pending(tls->ssl);
}
int tls_read(tls_t *tls, void * const buff, const size_t len) int tls_read(tls_t *tls, void * const buff, const size_t len)
{ {
int ret = SSL_read(tls->ssl, buff, len); int ret = SSL_read(tls->ssl, buff, len);