From 994f8b554fadc41783258b523c1230c4f21beadb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 9 Oct 2014 19:56:44 +0200 Subject: [PATCH] Ok for close_notify to fail --- programs/ssl/ssl_client2.c | 23 ++++++----------------- programs/ssl/ssl_server2.c | 23 ++++++----------------- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 599699481..330276c11 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -1336,24 +1336,13 @@ send_request: close_notify: printf( " . Closing the connection..." ); - while( ( ret = ssl_close_notify( &ssl ) ) < 0 ) - { - if( ret == POLARSSL_ERR_NET_CONN_RESET ) - { - printf( " ok (already closed by peer)\n" ); - ret = 0; - goto reconnect; - } + /* No error checking, the connection might be closed already */ + do + ret = ssl_close_notify( &ssl ); + while( ret == POLARSSL_ERR_NET_WANT_WRITE ); + ret = 0; - if( ret != POLARSSL_ERR_NET_WANT_READ && - ret != POLARSSL_ERR_NET_WANT_WRITE ) - { - printf( " failed\n ! ssl_close_notify returned %d\n\n", ret ); - goto reconnect; - } - } - - printf( " ok\n" ); + printf( " done\n" ); /* * 9. Reconnect? diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index 738c51ffb..9e0a2406f 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -1949,24 +1949,13 @@ data_exchange: close_notify: printf( " . Closing the connection..." ); - while( ( ret = ssl_close_notify( &ssl ) ) < 0 ) - { - if( ret == POLARSSL_ERR_NET_CONN_RESET ) - { - printf( " ok (already closed by peer)\n" ); - ret = 0; - goto reset; - } + /* No error checking, the connection might be closed already */ + do + ret = ssl_close_notify( &ssl ); + while( ret == POLARSSL_ERR_NET_WANT_WRITE ); + ret = 0; - if( ret != POLARSSL_ERR_NET_WANT_READ && - ret != POLARSSL_ERR_NET_WANT_WRITE ) - { - printf( " failed\n ! ssl_close_notify returned %d\n\n", ret ); - goto reset; - } - } - - printf( " ok\n" ); + printf( " done\n" ); goto reset; /*