From a194849b9e9ed6dfb7a284d8c6becf8033c58cd0 Mon Sep 17 00:00:00 2001 From: cameronrich Date: Fri, 18 May 2007 22:25:23 +0000 Subject: [PATCH] fixed partial write error git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@94 9a5d90b5-6617-0410-8a86-bb477d3ed2e3 --- ssl/tls1.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/ssl/tls1.c b/ssl/tls1.c index 2cb497643..43d798ed6 100755 --- a/ssl/tls1.c +++ b/ssl/tls1.c @@ -918,7 +918,8 @@ static int send_raw_packet(SSL *ssl, uint8_t protocol) { uint8_t *rec_buf = ssl->bm_all_data; int pkt_size = SSL_RECORD_SIZE+ssl->bm_index; - int ret; + int sent = 0; + int ret = SSL_OK; rec_buf[0] = protocol; rec_buf[1] = 0x03; /* version = 3.1 (TLS) */ @@ -927,11 +928,33 @@ static int send_raw_packet(SSL *ssl, uint8_t protocol) rec_buf[4] = ssl->bm_index & 0xff; DISPLAY_BYTES(ssl, "sending %d bytes", ssl->bm_all_data, - pkt_size, pkt_size); + pkt_size, pkt_size); - if ((ret = SOCKET_WRITE(ssl->client_fd, - ssl->bm_all_data, pkt_size)) < 0) - ret = SSL_ERROR_CONN_LOST; + while (sent < pkt_size) + { + if ((ret = SOCKET_WRITE(ssl->client_fd, + &ssl->bm_all_data[sent], pkt_size)) < 0) + { + ret = SSL_ERROR_CONN_LOST; + break; + } + + sent += ret; + + /* keep going until the write buffer has some space */ + if (sent != pkt_size) + { + fd_set wfds; + FD_ZERO(&wfds); + FD_SET(ssl->client_fd, &wfds); + + if (select(ssl->client_fd + 1, NULL, &wfds, NULL, NULL) < 0) + { + ret = SSL_ERROR_CONN_LOST; + break; + } + } + } SET_SSL_FLAG(SSL_NEED_RECORD); /* reset for next time */ ssl->bm_index = 0;