- Timestamp:
- Nov 6, 2009 8:01:59 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/ssl_sock_ossl.c
r2986 r2989 37 37 #define THIS_FILE "ssl_sock_ossl.c" 38 38 39 /* Workaround for ticket #985 */ 40 #define DELAYED_CLOSE_TIMEOUT 200 41 39 42 /* 40 43 * Include OpenSSL headers … … 63 66 SSL_STATE_HANDSHAKING, 64 67 SSL_STATE_ESTABLISHED 68 }; 69 70 /* 71 * Internal timer types. 72 */ 73 enum timer_id 74 { 75 TIMER_NONE, 76 TIMER_HANDSHAKE_TIMEOUT, 77 TIMER_CLOSE 65 78 }; 66 79 … … 139 152 enum ssl_state ssl_state; 140 153 pj_ioqueue_op_key_t handshake_op_key; 141 pj_timer_entry handshake_timer;154 pj_timer_entry timer; 142 155 143 156 pj_sock_t sock; … … 696 709 { 697 710 /* 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 } 700 715 701 716 /* Update certificates info on successful handshake */ … … 717 732 errmsg)); 718 733 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 } 720 754 return PJ_FALSE; 721 755 } … … 875 909 876 910 877 static void handshake_timeout_cb(pj_timer_heap_t *th, 878 struct pj_timer_entry *te) 911 static void on_timer(pj_timer_heap_t *th, struct pj_timer_entry *te) 879 912 { 880 913 pj_ssl_sock_t *ssock = (pj_ssl_sock_t*)te->user_data; 914 int timer_id = te->id; 915 916 te->id = TIMER_NONE; 881 917 882 918 PJ_UNUSED_ARG(th); 883 919 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 } 888 934 } 889 935 … … 1253 1299 ssock->param.timeout.msec != 0)) 1254 1300 { 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; 1259 1308 } 1260 1309 … … 1348 1397 ssock->param.timeout.msec != 0)) 1349 1398 { 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; 1355 1406 } 1356 1407 … … 1487 1538 pj_list_init(&ssock->write_pending); 1488 1539 pj_list_init(&ssock->write_pending_empty); 1540 pj_timer_entry_init(&ssock->timer, 0, ssock, &on_timer); 1489 1541 1490 1542 /* Create secure socket mutex */ … … 1526 1578 1527 1579 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 } 1528 1588 1529 1589 reset_ssl_sock_state(ssock);
Note: See TracChangeset
for help on using the changeset viewer.