Commit 5574bccf authored by Pekka Pessi's avatar Pekka Pessi

tport: fixed problem with tls send blocking

darcs-hash:20071008190004-55b16-fdc14ae904f056732c8b11c8ccb6e05da857a050.gz
parent 5d7ad669
......@@ -664,22 +664,30 @@ int tls_pending(tls_t const *tls)
return tls && tls->con && SSL_pending(tls->con);
}
/** Check if data is available in TCP connection.
*
*
*
* @retval -1 upon an error
* @retval 0 end-of-stream
* @retval 1 nothing to read
* @retval 2 there is data to read
*/
int tls_want_read(tls_t *tls, int events)
{
if (tls && (events & tls->read_events)) {
int ret = tls_read(tls);
if (ret > 0)
return 1;
return 2;
else if (ret == 0)
return 0;
else if (errno == EAGAIN)
return 2;
return 3; /* ??? */
else
return -1;
}
return 0;
return 1;
}
ssize_t tls_write(tls_t *tls, void *buf, size_t size)
......
......@@ -304,12 +304,23 @@ int tport_tls_events(tport_t *self, int events)
}
if ((self->tp_events & SU_WAIT_IN) && !self->tp_closed) {
ret = tls_want_read(tlstp->tlstp_context, events);
if (ret > 0)
tport_recv_event(self);
else if (ret == 0) /* End-of-stream */
for (;;) {
ret = tls_want_read(tlstp->tlstp_context, events);
if (ret > 1) {
tport_recv_event(self);
if ((events & SU_WAIT_HUP) && !self->tp_closed)
continue;
}
break;
}
if (ret == 0) { /* End-of-stream */
if (self->tp_msg)
tport_recv_event(self);
tport_shutdown0(self, 2);
else if (ret < 0)
}
if (ret < 0)
tport_error_report(self, errno, NULL);
}
......@@ -363,8 +374,11 @@ int tport_tls_recv(tport_t *self)
SU_DEBUG_7(("%s(%p): tls_read() returned "MOD_ZD"\n", __func__, (void *)self, N));
if (N == 0) /* End-of-stream */
if (N == 0) {
if (self->tp_msg)
msg_recv_commit(self->tp_msg, 0, 1); /* End-of-stream */
return 0;
}
else if (N == -1) {
if (su_is_blocking(su_errno())) {
tport_tls_set_events(self);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment