]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
some cleanups and better handling of EOF in record_recv.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 22 May 2004 19:37:06 +0000 (19:37 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 22 May 2004 19:37:06 +0000 (19:37 +0000)
lib/gnutls_int.h
lib/gnutls_record.c

index 47aecbfb79ade8f2ccf54c502f340a4c69c4d1f7..982525d723669b168de92375938d7e25574e15a7 100644 (file)
@@ -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 */
 
index 1691e7e236863b93d241da6b070206a82ab56a4f..f31c55c21975c7cd07762ca213876ecdc924b6c7 100644 (file)
@@ -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;
        }