diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 330276c11..0db53dbd0 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -1211,17 +1211,37 @@ send_request: if( len >= 1 ) buf[len - 1] = '\n'; } - for( written = 0, frags = 0; written < len; written += ret, frags++ ) + if( opt.transport == SSL_TRANSPORT_STREAM ) { - while( ( ret = ssl_write( &ssl, buf + written, len - written ) ) <= 0 ) + for( written = 0, frags = 0; written < len; written += ret, frags++ ) { - if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE ) + while( ( ret = ssl_write( &ssl, buf + written, len - written ) ) + <= 0 ) { - printf( " failed\n ! ssl_write returned -0x%x\n\n", -ret ); - goto exit; + if( ret != POLARSSL_ERR_NET_WANT_READ && + ret != POLARSSL_ERR_NET_WANT_WRITE ) + { + printf( " failed\n ! ssl_write returned -0x%x\n\n", -ret ); + goto exit; + } } } } + else /* Not stream, so datagram */ + { + do ret = ssl_write( &ssl, buf, len ); + while( ret == POLARSSL_ERR_NET_WANT_READ || + ret == POLARSSL_ERR_NET_WANT_WRITE ); + + if( ret < 0 ) + { + printf( " failed\n ! ssl_write returned %d\n\n", ret ); + goto exit; + } + + frags = 1; + written = ret; + } buf[written] = '\0'; printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf ); diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index 9e0a2406f..7fac0ab0a 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -1915,23 +1915,43 @@ data_exchange: len = sprintf( (char *) buf, HTTP_RESPONSE, ssl_get_ciphersuite( &ssl ) ); - for( written = 0, frags = 0; written < len; written += ret, frags++ ) + if( opt.transport == SSL_TRANSPORT_STREAM ) { - while( ( ret = ssl_write( &ssl, buf + written, len - written ) ) <= 0 ) + for( written = 0, frags = 0; written < len; written += ret, frags++ ) { - if( ret == POLARSSL_ERR_NET_CONN_RESET ) + while( ( ret = ssl_write( &ssl, buf + written, len - written ) ) + <= 0 ) { - printf( " failed\n ! peer closed the connection\n\n" ); - goto reset; - } + if( ret == POLARSSL_ERR_NET_CONN_RESET ) + { + printf( " failed\n ! peer closed the connection\n\n" ); + goto reset; + } - if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE ) - { - printf( " failed\n ! ssl_write returned %d\n\n", ret ); - goto reset; + if( ret != POLARSSL_ERR_NET_WANT_READ && + ret != POLARSSL_ERR_NET_WANT_WRITE ) + { + printf( " failed\n ! ssl_write returned %d\n\n", ret ); + goto reset; + } } } } + else /* Not stream, so datagram */ + { + do ret = ssl_write( &ssl, buf, len ); + while( ret == POLARSSL_ERR_NET_WANT_READ || + ret == POLARSSL_ERR_NET_WANT_WRITE ); + + if( ret < 0 ) + { + printf( " failed\n ! ssl_write returned %d\n\n", ret ); + goto reset; + } + + frags = 1; + written = ret; + } buf[written] = '\0'; printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf );