Changeset 1838

Show
Ignore:
Timestamp:
08/15/08 00:27:24 (3 months ago)
Author:
alo
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee/trunk/ChangeLog

    r1837 r1838  
    112008-08-14  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
     2 
     3        * cherokee/socket.c, cherokee/socket.h, cherokee/thread.c, 
     4        cherokee/thread.h, cherokee/connection.c: Fixes the TLS/SSL 
     5        support. It adds support for a new concept within the server: a 
     6        cherokee_buffer_t can have pending information to be read, so in 
     7        addition to the file descriptor this property must be checked 
     8        whenever it real status need to be known. 
    29 
    310        * qa/run-tests.py, qa/base.py: Fixes two minor issues. 
  • cherokee/trunk/cherokee/connection.c

    r1814 r1838  
    717717        case ret_eof: 
    718718        case ret_error: 
     719                return ret; 
     720 
    719721        case ret_eagain: 
    720                 return ret; 
     722                if (cherokee_socket_pending_read (&conn->socket)) { 
     723                        CONN_THREAD(conn)->pending_read_num += 1; 
     724                } 
     725                return ret_eagain; 
    721726 
    722727        default: 
  • cherokee/trunk/cherokee/socket.c

    r1790 r1838  
    11411141 
    11421142        if (likely (len > 0)) { 
    1143                 *pcnt_read = len; 
     1143                *pcnt_read = len; 
     1144                if (gnutls_record_check_pending (socket->session) > 0) 
     1145                        return ret_eagain; 
    11441146                return ret_ok; 
    11451147        } 
     
    11711173#elif defined (HAVE_OPENSSL) 
    11721174        len = SSL_read (socket->session, buf, buf_size); 
    1173  
    11741175        if (likely (len > 0)) { 
    11751176                *pcnt_read = len; 
     1177                if (SSL_pending (socket->session)) 
     1178                        return ret_eagain; 
    11761179                return ret_ok; 
    11771180        } 
     
    11841187        {       /* len < 0 */ 
    11851188                int re; 
     1189                int error = errno; 
    11861190 
    11871191                re = SSL_get_error (socket->session, len); 
     
    11951199                case SSL_ERROR_SSL:          
    11961200                        return ret_error; 
     1201                case SSL_ERROR_SYSCALL: 
     1202                        switch (error) { 
     1203                        case EPIPE: 
     1204                        case ECONNRESET: 
     1205                                socket->status = socket_closed; 
     1206                                return ret_eof; 
     1207                        default: 
     1208                                PRINT_ERRNO (error, "SSL_read: unknown errno: ${errno}\n"); 
     1209                        } 
     1210                        return ret_error; 
    11971211                } 
    11981212 
     
    12071221#endif  /* HAVE_TLS */ 
    12081222 
     1223} 
     1224 
     1225 
     1226int 
     1227cherokee_socket_pending_read (cherokee_socket_t *socket) 
     1228{ 
     1229        if (socket->is_tls != TLS) 
     1230                return 0; 
     1231 
     1232        if (unlikely ((socket->status != socket_reading) && 
     1233                      (socket->status != socket_writing))) 
     1234                return 0; 
     1235 
     1236#ifdef HAVE_TLS 
     1237# ifdef HAVE_GNUTLS 
     1238        return (gnutls_record_check_pending (socket->session) > 0); 
     1239# elif defined (HAVE_OPENSSL) 
     1240        return (SSL_pending (socket->session) > 0); 
     1241# endif 
     1242#endif 
    12091243} 
    12101244 
     
    13751409 */ 
    13761410ret_t       
    1377 cherokee_socket_bufread (cherokee_socket_t *socket, cherokee_buffer_t *buf, size_t count, size_t *pcnt_read) 
     1411cherokee_socket_bufread (cherokee_socket_t *socket,  
     1412                         cherokee_buffer_t *buf,  
     1413                         size_t             count,  
     1414                         size_t            *pcnt_read) 
    13781415{ 
    13791416        ret_t    ret; 
     
    13871424 
    13881425        starting = buf->buf + buf->len; 
    1389  
     1426         
    13901427        ret = cherokee_socket_read (socket, starting, count, pcnt_read); 
    1391         if (ret == ret_ok) { 
     1428        if (*pcnt_read > 0) { 
    13921429                buf->len += *pcnt_read; 
    13931430                buf->buf[buf->len] = '\0'; 
  • cherokee/trunk/cherokee/socket.h

    r1790 r1838  
    191191ret_t cherokee_socket_shutdown          (cherokee_socket_t *socket, int how); 
    192192ret_t cherokee_socket_accept            (cherokee_socket_t *socket, int server_socket); 
     193int   cherokee_socket_pending_read      (cherokee_socket_t *socket); 
    193194 
    194195ret_t cherokee_socket_set_client        (cherokee_socket_t *socket, unsigned short int type); 
  • cherokee/trunk/cherokee/thread.c

    r1814 r1838  
    155155        n->polling_list_num   = 0; 
    156156        n->reuse_list_num     = 0; 
     157 
    157158        n->pending_conns_num  = 0; 
     159        n->pending_read_num   = 0; 
    158160 
    159161        n->fastcgi_servers    = NULL; 
     
    581583                 */ 
    582584                if ((conn->traffic_next < thd->bogo_now) && 
    583                     (conn->rx != 0) && 
    584                     (conn->tx != 0))
     585                    ((conn->rx != 0) || (conn->tx != 0))) 
     586               
    585587                        cherokee_connection_update_vhost_traffic (conn); 
    586588                } 
     
    603605                                continue; 
    604606                        case 0: 
    605                                 continue; 
     607                                if (! cherokee_socket_pending_read (&conn->socket)) 
     608                                        continue; 
    606609                        } 
    607610                } 
     
    15091512        } 
    15101513 
     1514        if (thd->pending_read_num > 0) { 
     1515                fdwatch_msecs         = 0; 
     1516                thd->pending_read_num = 0; 
     1517        } 
     1518 
    15111519        re = cherokee_fdpoll_watch (thd->fdpoll, fdwatch_msecs); 
    15121520        if (re <= 0) 
     
    18521860                fdwatch_msecs          = 0; 
    18531861                thd->pending_conns_num = 0; 
     1862        } 
     1863 
     1864        if (thd->pending_read_num > 0) { 
     1865                fdwatch_msecs         = 0; 
     1866                thd->pending_read_num = 0; 
    18541867        } 
    18551868 
  • cherokee/trunk/cherokee/thread.h

    r1763 r1838  
    8686 
    8787        int                     pending_conns_num;  /* Waiting pipelining connections */ 
    88  
     88        int                     pending_read_num;   /* Conns with SSL deping read */ 
     89         
    8990        struct { 
    9091                uint32_t        continuous;