[PATCH] Fix sending long commands when using gnutls
Hi,
mutt (with enabled gnutls support) hangs when trying to send IMAP
commands longer than 16KB. This is caused by gnutls_record_send(),
which returns after sending one message block instead of sending all
data from the buffer.
# HG changeset patch
# User Miroslav Lichvar <mlichvar@xxxxxxxxxx>
# Date 1207235293 -7200
# Branch HEAD
# Node ID c10d4343a17f8576e1f99b795c3ac53d01043279
# Parent e3bc99a4a6bde15d0c411b557d1dec6f8596f499
Fix sending long commands when using gnutls.
diff -r e3bc99a4a6bd -r c10d4343a17f mutt_ssl_gnutls.c
--- a/mutt_ssl_gnutls.c Tue Mar 11 17:20:48 2008 -0700
+++ b/mutt_ssl_gnutls.c Thu Apr 03 17:08:13 2008 +0200
@@ -112,6 +112,7 @@ static int tls_socket_write (CONNECTION*
{
tlssockdata *data = conn->sockdata;
int ret;
+ size_t sent = 0;
if (!data)
{
@@ -120,14 +121,23 @@ static int tls_socket_write (CONNECTION*
return -1;
}
- ret = gnutls_record_send (data->state, buf, len);
- if (ret < 0 && gnutls_error_is_fatal(ret) == 1)
+ do
{
- mutt_error ("tls_socket_write (%s)", gnutls_strerror (ret));
- mutt_sleep (4);
- return -1;
- }
- return ret;
+ ret = gnutls_record_send (data->state, buf + sent, len - sent);
+ if (ret < 0)
+ {
+ if (gnutls_error_is_fatal(ret) == 1)
+ {
+ mutt_error ("tls_socket_write (%s)", gnutls_strerror (ret));
+ mutt_sleep (4);
+ return -1;
+ }
+ return ret;
+ }
+ sent += ret;
+ } while (sent < len);
+
+ return sent;
}
static int tls_socket_open (CONNECTION* conn)
--
Miroslav Lichvar