Ignore:
Timestamp:
Nov 4, 2009 5:08:32 PM (14 years ago)
Author:
nanang
Message:

Ticket #957:

  • Applied workaround solution for getting local address problem with getsockname on win IOCP by using parent local address instead.
  • Fixed SSL socket not to return PJ_FALSE in active socket accept callback, to keep accepting connections.
  • Applied workaround solution for OpenSSL error mapping, as OpenSSL error codes are big numbers that won't fit pj_status_t.
  • Minor updates, e.g: using pj_perror(), removing some logs, OpenSSL error print callback.
  • Minor updates on SSL unit test, e.g: start_read() before start sending, additional ioqueue poll to cleanup sockets, add timeout feature to https client test.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pjlib-test/ssl_sock.c

    r2981 r2986  
    151151    } 
    152152 
     153    /* Start reading data */ 
     154    read_buf[0] = st->read_buf; 
     155    status = pj_ssl_sock_start_read2(ssock, st->pool, sizeof(st->read_buf), (void**)read_buf, 0); 
     156    if (status != PJ_SUCCESS) { 
     157        app_perror("...ERROR pj_ssl_sock_start_read2()", status); 
     158        goto on_return; 
     159    } 
     160 
    153161    /* Start sending data */ 
    154162    while (st->sent < st->send_str_len) { 
     
    169177    } 
    170178 
    171     /* Start reading data */ 
    172     read_buf[0] = st->read_buf; 
    173     status = pj_ssl_sock_start_read2(ssock, st->pool, sizeof(st->read_buf), (void**)read_buf, 0); 
    174     if (status != PJ_SUCCESS  && status != PJ_EPENDING) { 
    175         app_perror("...ERROR pj_ssl_sock_start_read2()", status); 
    176         goto on_return; 
    177     } 
    178  
    179179on_return: 
    180180    st->err = status; 
     
    196196{ 
    197197    struct test_state *parent_st = (struct test_state*)  
    198                             pj_ssl_sock_get_user_data(ssock); 
     198                                   pj_ssl_sock_get_user_data(ssock); 
    199199    struct test_state *st; 
    200200    void *read_buf[1]; 
     
    237237            dump_cert_info(".......", &info.remote_cert_info); 
    238238        } 
     239    } 
     240 
     241    /* Start reading data */ 
     242    read_buf[0] = st->read_buf; 
     243    status = pj_ssl_sock_start_read2(newsock, st->pool, sizeof(st->read_buf), (void**)read_buf, 0); 
     244    if (status != PJ_SUCCESS) { 
     245        app_perror("...ERROR pj_ssl_sock_start_read2()", status); 
     246        goto on_return; 
    239247    } 
    240248 
     
    255263        else 
    256264            break; 
    257     } 
    258  
    259     /* Start reading data */ 
    260     read_buf[0] = st->read_buf; 
    261     status = pj_ssl_sock_start_read2(newsock, st->pool, sizeof(st->read_buf), (void**)read_buf, 0); 
    262     if (status != PJ_SUCCESS  && status != PJ_EPENDING) { 
    263         app_perror("...ERROR pj_ssl_sock_start_read2()", status); 
    264         goto on_return; 
    265265    } 
    266266 
     
    422422#define HTTP_SERVER_PORT        443 
    423423 
    424 static int https_client_test(void) 
     424static int https_client_test(unsigned ms_timeout) 
    425425{ 
    426426    pj_pool_t *pool = NULL; 
    427427    pj_ioqueue_t *ioqueue = NULL; 
     428    pj_timer_heap_t *timer = NULL; 
    428429    pj_ssl_sock_t *ssock = NULL; 
    429430    pj_ssl_sock_param param; 
     
    436437 
    437438    status = pj_ioqueue_create(pool, 4, &ioqueue); 
     439    if (status != PJ_SUCCESS) { 
     440        goto on_return; 
     441    } 
     442 
     443    status = pj_timer_heap_create(pool, 4, &timer); 
    438444    if (status != PJ_SUCCESS) { 
    439445        goto on_return; 
     
    452458    param.user_data = &state; 
    453459    param.server_name = pj_str((char*)HTTP_SERVER_ADDR); 
     460    param.timer_heap = timer; 
     461    param.timeout.sec = 0; 
     462    param.timeout.msec = ms_timeout; 
     463    pj_time_val_normalize(&param.timeout); 
    454464 
    455465    status = pj_ssl_sock_create(pool, &param, &ssock); 
     
    476486        pj_time_val delay = {0, 100}; 
    477487        pj_ioqueue_poll(ioqueue, &delay); 
     488        pj_timer_heap_poll(timer, &delay); 
    478489#endif 
    479490    } 
     
    492503    if (ioqueue) 
    493504        pj_ioqueue_destroy(ioqueue); 
     505    if (timer) 
     506        pj_timer_heap_destroy(timer); 
    494507    if (pool) 
    495508        pj_pool_release(pool); 
     
    633646    } 
    634647 
     648    /* Clean up sockets */ 
     649    { 
     650        pj_time_val delay = {0, 100}; 
     651        while (pj_ioqueue_poll(ioqueue, &delay) > 0); 
     652    } 
     653 
    635654    if (state_serv.err || state_cli.err) { 
    636655        if (state_serv.err != PJ_SUCCESS) 
     
    683702    st->err = status; 
    684703 
     704    if (st->err != PJ_SUCCESS || st->done) { 
     705        pj_activesock_close(asock); 
     706        if (!st->is_server) 
     707            clients_num--; 
     708        return PJ_FALSE; 
     709    } 
     710 
    685711    return PJ_TRUE; 
    686712} 
     
    694720 
    695721    if (status == PJ_SUCCESS) { 
    696         status = pj_activesock_start_read(asock, st->pool, 1, 0); 
     722        void *read_buf[1]; 
     723 
     724        /* Start reading data */ 
     725        read_buf[0] = st->read_buf; 
     726        status = pj_activesock_start_read2(asock, st->pool, sizeof(st->read_buf), (void**)read_buf, 0); 
     727        if (status != PJ_SUCCESS) { 
     728            app_perror("...ERROR pj_ssl_sock_start_read2()", status); 
     729        } 
    697730    } 
    698731 
    699732    st->err = status; 
     733 
     734    if (st->err != PJ_SUCCESS) { 
     735        pj_activesock_close(asock); 
     736        if (!st->is_server) 
     737            clients_num--; 
     738        return PJ_FALSE; 
     739    } 
    700740 
    701741    return PJ_TRUE; 
     
    846886    if (ssock_serv) 
    847887        pj_ssl_sock_close(ssock_serv); 
    848     if (asock_cli) 
     888    if (asock_cli && !state_cli.err && !state_cli.done) 
    849889        pj_activesock_close(asock_cli); 
    850890    if (timer) 
     
    859899 
    860900 
     901/* Test will perform multiple clients trying to connect to single server. 
     902 * Once SSL connection established, echo test will be performed. 
     903 */ 
    861904static int perf_test(unsigned clients, unsigned ms_handshake_timeout) 
    862905{ 
     
    10231066    } 
    10241067 
     1068    /* Clean up sockets */ 
     1069    { 
     1070        pj_time_val delay = {0, 500}; 
     1071        while (pj_ioqueue_poll(ioqueue, &delay) > 0); 
     1072    } 
     1073 
    10251074    if (state_serv.err != PJ_SUCCESS) { 
    10261075        status = state_serv.err; 
     
    10781127        return ret; 
    10791128 
    1080     // Disable this test as requiring internet connection. 
    1081 #if 0 
    10821129    PJ_LOG(3,("", "..https client test")); 
    1083     ret = https_client_test(); 
    1084     if (ret != 0) 
    1085         return ret; 
    1086 #endif 
     1130    ret = https_client_test(30000); 
     1131    // Ignore test result as internet connection may not be available. 
     1132    //if (ret != 0) 
     1133        //return ret; 
     1134 
     1135#ifndef PJ_SYMBIAN 
    10871136 
    10881137    PJ_LOG(3,("", "..echo test w/ TLSv1 and TLS_RSA_WITH_DES_CBC_SHA cipher")); 
     
    11101159        return PJ_EBUG; 
    11111160 
    1112     PJ_LOG(3,("", "..client non-SSL timeout in 5 secs")); 
     1161    PJ_LOG(3,("", "..client non-SSL (handshake timeout 5 secs)")); 
    11131162    ret = client_non_ssl(5000); 
    11141163    if (ret != 0) 
     
    11191168    if (ret != 0) 
    11201169        return ret; 
     1170 
     1171#endif 
    11211172 
    11221173    return 0; 
Note: See TracChangeset for help on using the changeset viewer.