From: Nikos Mavrogiannopoulos Date: Sat, 22 May 2004 19:37:06 +0000 (+0000) Subject: some cleanups and better handling of EOF in record_recv. X-Git-Tag: gnutls_1_1_11~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b5cc3a39b8071c464e65c73b41dfb782e59c9df;p=thirdparty%2Fgnutls.git some cleanups and better handling of EOF in record_recv. --- diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h index 47aecbfb79..982525d723 100644 --- a/lib/gnutls_int.h +++ b/lib/gnutls_int.h @@ -484,9 +484,10 @@ typedef struct { ValidSession valid_connection; /* true or FALSE - if this session is valid */ - int may_read; /* if it's 0 then we can read/write, otherwise it's forbiden to read/write + int may_not_read; /* if it's 0 then we can read/write, otherwise it's forbiden to read/write */ - int may_write; + int may_not_write; + int read_eof; /* non-zero if we have received a closure alert. */ int last_alert; /* last alert received */ diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c index 1691e7e236..f31c55c219 100644 --- a/lib/gnutls_record.c +++ b/lib/gnutls_record.c @@ -195,7 +195,7 @@ int gnutls_bye( gnutls_session session, gnutls_close_request how) case STATE62: if ( how == GNUTLS_SHUT_RDWR) { ret = _gnutls_recv_int( session, GNUTLS_ALERT, -1, NULL, 0); - if (ret >= 0) session->internals.may_read = 1; + if (ret >= 0) session->internals.may_not_read = 1; } STATE = STATE62; @@ -211,7 +211,7 @@ int gnutls_bye( gnutls_session session, gnutls_close_request how) STATE = STATE0; - session->internals.may_write = 1; + session->internals.may_not_write = 1; return 0; } @@ -292,7 +292,7 @@ ssize_t _gnutls_send_int( gnutls_session session, ContentType type, } if (type!=GNUTLS_ALERT) /* alert messages are sent anyway */ - if ( _gnutls_session_is_valid( session) || session->internals.may_write != 0) { + if ( _gnutls_session_is_valid( session) || session->internals.may_not_write != 0) { gnutls_assert(); return GNUTLS_E_INVALID_SESSION; } @@ -547,7 +547,7 @@ static int _gnutls_record_check_type( gnutls_session session, ContentType recv_t if (data[1] == GNUTLS_A_CLOSE_NOTIFY && data[0] != GNUTLS_AL_FATAL) { /* If we have been expecting for an alert do */ - + session->internals.read_eof = 1; return GNUTLS_E_INT_RET_0; /* EOF */ } else { @@ -696,7 +696,11 @@ ssize_t _gnutls_recv_int( gnutls_session session, ContentType type, return GNUTLS_E_TOO_MANY_EMPTY_PACKETS; } - if ( _gnutls_session_is_valid(session)!=0 || session->internals.may_read!=0) { + if (session->internals.read_eof != 0) { + /* if we have already read an EOF + */ + return 0; + } else if ( _gnutls_session_is_valid(session)!=0 || session->internals.may_not_read!=0) { gnutls_assert(); return GNUTLS_E_INVALID_SESSION; }