Description: attempt to write to the socket multiple times until all data has been written Author: Ludovico Cavedon Index: proxytunnel-1.9.0/ptstream.c =================================================================== --- proxytunnel-1.9.0.orig/ptstream.c 2013-07-24 12:45:01.000000000 -0700 +++ proxytunnel-1.9.0/ptstream.c 2013-07-24 13:59:10.325875786 -0700 @@ -98,21 +98,36 @@ int stream_write(PTSTREAM *pts, void *buf, size_t len) { /* Write the specified number of bytes from the buffer */ int bytes_written; + int total_bytes_written = 0; - if (!pts->ssl) { - /* For a non-SSL stream... */ - bytes_written = write(pts->outgoing_fd, buf, len); - } else { + while (total_bytes_written < len) { + if (!pts->ssl) { + /* For a non-SSL stream... */ + bytes_written = write(pts->outgoing_fd, + buf + total_bytes_written, + len - total_bytes_written); + } else { #ifdef USE_SSL - /* For an SSL stream... */ - bytes_written = gnutls_record_send(pts->session, buf, len); + /* For an SSL stream... */ + bytes_written = gnutls_record_send(pts->session, + buf + total_bytes_written, + len - total_bytes_written + ); #else - /* No SSL support, so must use a non-SSL stream */ - bytes_written = write(pts->outgoing_fd, buf, len); + /* No SSL support, so must use a non-SSL stream */ + bytes_written = write(pts->outgoing_fd, + buf + total_bytes_written, + len - total_bytes_written); #endif /* USE_SSL */ + } + + if (bytes_written <= 0) { + break; + } + total_bytes_written += bytes_written; } - return bytes_written; + return total_bytes_written; }