Changeset 2989 for pjproject


Ignore:
Timestamp:
Nov 6, 2009 8:01:59 AM (14 years ago)
Author:
nanang
Message:

Ticket #957: Workaround fix for SSL socket specific related to ticket #985.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/ssl_sock_ossl.c

    r2986 r2989  
    3737#define THIS_FILE               "ssl_sock_ossl.c" 
    3838 
     39/* Workaround for ticket #985 */ 
     40#define DELAYED_CLOSE_TIMEOUT   200 
     41 
    3942/*  
    4043 * Include OpenSSL headers  
     
    6366    SSL_STATE_HANDSHAKING, 
    6467    SSL_STATE_ESTABLISHED 
     68}; 
     69 
     70/* 
     71 * Internal timer types. 
     72 */ 
     73enum timer_id 
     74{ 
     75    TIMER_NONE, 
     76    TIMER_HANDSHAKE_TIMEOUT, 
     77    TIMER_CLOSE 
    6578}; 
    6679 
     
    139152    enum ssl_state        ssl_state; 
    140153    pj_ioqueue_op_key_t   handshake_op_key; 
    141     pj_timer_entry        handshake_timer; 
     154    pj_timer_entry        timer; 
    142155 
    143156    pj_sock_t             sock; 
     
    696709{ 
    697710    /* Cancel handshake timer */ 
    698     if (ssock->param.timer_heap) 
    699         pj_timer_heap_cancel(ssock->param.timer_heap, &ssock->handshake_timer); 
     711    if (ssock->timer.id == TIMER_HANDSHAKE_TIMEOUT) { 
     712        pj_timer_heap_cancel(ssock->param.timer_heap, &ssock->timer); 
     713        ssock->timer.id = TIMER_NONE; 
     714    } 
    700715 
    701716    /* Update certificates info on successful handshake */ 
     
    717732                      errmsg)); 
    718733 
    719             pj_ssl_sock_close(ssock); 
     734            /* Workaround for ticket #985 */ 
     735#if defined(PJ_WIN32) && PJ_WIN32!=0 
     736            if (ssock->param.timer_heap) { 
     737                pj_time_val interval = {0, DELAYED_CLOSE_TIMEOUT}; 
     738 
     739                reset_ssl_sock_state(ssock); 
     740 
     741                ssock->timer.id = TIMER_CLOSE; 
     742                pj_time_val_normalize(&interval); 
     743                if (pj_timer_heap_schedule(ssock->param.timer_heap,  
     744                                           &ssock->timer, &interval) != 0) 
     745                { 
     746                    ssock->timer.id = TIMER_NONE; 
     747                    pj_ssl_sock_close(ssock); 
     748                } 
     749            } else  
     750#endif  /* PJ_WIN32 */ 
     751            { 
     752                pj_ssl_sock_close(ssock); 
     753            } 
    720754            return PJ_FALSE; 
    721755        } 
     
    875909 
    876910 
    877 static void handshake_timeout_cb(pj_timer_heap_t *th, 
    878                                  struct pj_timer_entry *te) 
     911static void on_timer(pj_timer_heap_t *th, struct pj_timer_entry *te) 
    879912{ 
    880913    pj_ssl_sock_t *ssock = (pj_ssl_sock_t*)te->user_data; 
     914    int timer_id = te->id; 
     915 
     916    te->id = TIMER_NONE; 
    881917 
    882918    PJ_UNUSED_ARG(th); 
    883919 
    884     PJ_LOG(1,(ssock->pool->obj_name, "SSL handshake timeout after %d.%ds", 
    885               ssock->param.timeout.sec, ssock->param.timeout.msec)); 
    886  
    887     on_handshake_complete(ssock, PJ_ETIMEDOUT); 
     920    switch (timer_id) { 
     921    case TIMER_HANDSHAKE_TIMEOUT: 
     922        PJ_LOG(1,(ssock->pool->obj_name, "SSL handshake timeout after %d.%ds", 
     923                  ssock->param.timeout.sec, ssock->param.timeout.msec)); 
     924 
     925        on_handshake_complete(ssock, PJ_ETIMEDOUT); 
     926        break; 
     927    case TIMER_CLOSE: 
     928        pj_ssl_sock_close(ssock); 
     929        break; 
     930    default: 
     931        pj_assert(!"Unknown timer"); 
     932        break; 
     933    } 
    888934} 
    889935 
     
    12531299        ssock->param.timeout.msec != 0)) 
    12541300    { 
    1255         pj_timer_entry_init(&ssock->handshake_timer, 0, ssock,  
    1256                             &handshake_timeout_cb); 
    1257         pj_timer_heap_schedule(ssock->param.timer_heap, &ssock->handshake_timer, 
    1258                                &ssock->param.timeout); 
     1301        pj_assert(ssock->timer.id == TIMER_NONE); 
     1302        ssock->timer.id = TIMER_HANDSHAKE_TIMEOUT; 
     1303        status = pj_timer_heap_schedule(ssock->param.timer_heap,  
     1304                                        &ssock->timer, 
     1305                                        &ssock->param.timeout); 
     1306        if (status != PJ_SUCCESS) 
     1307            ssock->timer.id = TIMER_NONE; 
    12591308    } 
    12601309 
     
    13481397        ssock->param.timeout.msec != 0)) 
    13491398    { 
    1350         pj_timer_entry_init(&ssock->handshake_timer, 0, ssock,  
    1351                             &handshake_timeout_cb); 
    1352         pj_timer_heap_schedule(ssock->param.timer_heap, 
    1353                                &ssock->handshake_timer, 
    1354                                &ssock->param.timeout); 
     1399        pj_assert(ssock->timer.id == TIMER_NONE); 
     1400        ssock->timer.id = TIMER_HANDSHAKE_TIMEOUT; 
     1401        status = pj_timer_heap_schedule(ssock->param.timer_heap, 
     1402                                        &ssock->timer, 
     1403                                        &ssock->param.timeout); 
     1404        if (status != PJ_SUCCESS) 
     1405            ssock->timer.id = TIMER_NONE; 
    13551406    } 
    13561407 
     
    14871538    pj_list_init(&ssock->write_pending); 
    14881539    pj_list_init(&ssock->write_pending_empty); 
     1540    pj_timer_entry_init(&ssock->timer, 0, ssock, &on_timer); 
    14891541 
    14901542    /* Create secure socket mutex */ 
     
    15261578 
    15271579    PJ_ASSERT_RETURN(ssock, PJ_EINVAL); 
     1580 
     1581    if (!ssock->pool) 
     1582        return PJ_SUCCESS; 
     1583 
     1584    if (ssock->timer.id != TIMER_NONE) { 
     1585        pj_timer_heap_cancel(ssock->param.timer_heap, &ssock->timer); 
     1586        ssock->timer.id = TIMER_NONE; 
     1587    } 
    15281588 
    15291589    reset_ssl_sock_state(ssock); 
Note: See TracChangeset for help on using the changeset viewer.