Module: sip-router
Branch: andrei/tcp_tls_changes
Commit: 4f2a8e0cf2878fc53953b48761858bdf9a397857
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4f2a8e0…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Mon Aug 16 01:12:41 2010 +0200
tls: fix partial write on write-wants-read queue flush
When flushing the queue the SSL_write() should be retried until
the queue is empty or there is an error (SSL_WANT_READ or
SSL_WANT_WRITE), since it is possible to have partial writes
smaller then the block size (SSL_write() will write at most 1
record when partial writes are enabled and with the
ssl_max_send_fragment option it is possible to set/have record
sizes smaller then typical writes).
---
modules/tls/sbufq.h | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/modules/tls/sbufq.h b/modules/tls/sbufq.h
index cd29ecb..d50a1a4 100644
--- a/modules/tls/sbufq.h
+++ b/modules/tls/sbufq.h
@@ -265,7 +265,8 @@ inline static int sbufq_flush(struct sbuffer_queue* q, int* flags,
}else{
q->offset+=n;
q->queued-=n;
- break;
+ /* no break: if we are here n < block_size => partial write
+ => the write should be retried */
}
}else{
if (unlikely(n<0))
Module: sip-router
Branch: andrei/tcp_tls_changes
Commit: 9318b4cbc6e78dd0f28860b0d89e649f9aa17125
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9318b4c…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Sun Aug 15 18:10:42 2010 +0200
tls: verbose debugging for SSL_ERROR_WANT_WRITE
Debugging messages for partial write and SSL_ERROR_WANT_WRITE
(enabled only if the tls module is compiled with
-DTLS_WR_DEBUG and -DTLS_RD_DEBUG).
---
modules/tls/tls_server.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/modules/tls/tls_server.c b/modules/tls/tls_server.c
index a910767..5ccf545 100644
--- a/modules/tls/tls_server.c
+++ b/modules/tls/tls_server.c
@@ -787,6 +787,10 @@ redo_wr:
/* this function should be called again => disallow
immediate closing of the connection */
send_flags->f &= ~SND_F_CON_CLOSE;
+ TLS_WR_TRACE("(%p) SSL_ERROR_WANT_WRITE partial write"
+ " (written %p , %d, rest_buf=%p"
+ " rest_len=%d))\n", c, buf, offs,
+ *rest_buf, *rest_len);
}
break; /* or goto end */
case SSL_ERROR_SSL:
@@ -1157,6 +1161,8 @@ ssl_read_skipped:
/* something was written => buffer not big enough to hold
everything => reset buffer & retry (the tcp_write already
happened if we are here) */
+ TLS_RD_TRACE("(%p) SSL_ERROR_WANT_WRITE partial write"
+ " (written %d), retrying\n", c, wr.used);
goto continue_ssl_read;
}
/* else write buffer too small, nothing written */