From 687f89beabb56555061ab7e2a9fadfba10705c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 13 Jan 2015 21:48:12 +0100 Subject: [PATCH] Don't check errors on ssl_close_notify() Depending on timing we might get different errors (conn_reset, write failed) and ignoring them all ends up being almost the same as just not checking errors. --- programs/ssl/ssl_client2.c | 20 +++----------------- programs/ssl/ssl_server2.c | 20 +++----------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 07dee7f582..71f5efa301 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -1284,24 +1284,10 @@ 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; - } + /* Don't check for errors, the connection might already be closed */ + ssl_close_notify( &ssl ); - 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 2980cf5689..9ecbdf1e7a 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -1763,24 +1763,10 @@ 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; - } + /* Don't check for errors, the connection might already be closed */ + ssl_close_notify( &ssl ); - 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; /*