Ignore:
Timestamp:
May 17, 2016 8:51:14 AM (8 years ago)
Author:
nanang
Message:

Re #1900: Various fixes in sock_uwp.cpp, mostly about error/exception handlings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/uwp/pjlib/src/pj/sock_uwp.cpp

    r5256 r5298  
    395395        concurrency::create_task(listener_sock->CancelIOAsync()).wait(); 
    396396    } 
     397    while (has_pending_recv) pj_thread_sleep(10); 
     398 
    397399    stream_sock = nullptr; 
    398400    datagram_sock = nullptr; 
     
    434436 
    435437    HRESULT err = 0; 
    436     try { 
    437         concurrency::create_task([this, addr]() { 
    438             HostName ^host; 
    439             int port; 
     438    concurrency::create_task([this, addr, &err]() { 
     439        HostName ^host; 
     440        int port; 
     441 
     442        try { 
    440443            sockaddr_to_hostname_port(addr, host, &port); 
    441444            if (pj_sockaddr_has_addr(addr)) { 
     
    450453                    return listener_sock->BindServiceNameAsync(port.ToString()); 
    451454            } 
    452         }).then([this, &err](concurrency::task<void> t) 
    453         { 
    454             try { 
     455        } catch (Exception^ e) { 
     456            err = e->HResult; 
     457        } 
     458    }).then([this, &err](concurrency::task<void> t) 
     459    { 
     460        try { 
     461            if (!err) 
    455462                t.get(); 
    456             } catch (Exception^ e) { 
    457                 err = e->HResult; 
    458             } 
    459         }).get(); 
    460     } catch (Exception^ e) { 
    461         err = e->HResult; 
    462     } 
     463        } catch (Exception^ e) { 
     464            err = e->HResult; 
     465        } 
     466    }).get(); 
    463467 
    464468    return (err? PJ_RETURN_OS_ERROR(err) : PJ_SUCCESS); 
     
    643647        auto cts_token = cts.get_token(); 
    644648        auto t = concurrency::create_task(socket_reader->LoadAsync(*len), 
    645                                             cts_token); 
     649                                          cts_token); 
    646650        *len = cancel_after_timeout(t, cts, READ_TIMEOUT) 
    647651            .then([this, len, buf, cts_token, &status] 
     
    668672    /* Non-blocking version */ 
    669673 
     674    concurrency::cancellation_token_source cts; 
     675    auto cts_token = cts.get_token(); 
     676 
    670677    has_pending_recv = PJ_TRUE; 
    671     concurrency::create_task(socket_reader->LoadAsync(*len)) 
    672         .then([this](concurrency::task<unsigned int> t_) 
     678    concurrency::create_task(socket_reader->LoadAsync(*len), cts_token) 
     679        .then([this, cts_token](concurrency::task<unsigned int> t_) 
    673680    { 
    674681        try { 
    675             // catch any exception 
     682            if (cts_token.is_canceled()) { 
     683                has_pending_recv = PJ_FALSE; 
     684 
     685                // invoke callback 
     686                if (cb.on_read) { 
     687                    (*cb.on_read)(this, -PJ_EUNKNOWN); 
     688                } 
     689                return; 
     690            } 
     691 
    676692            t_.get(); 
    677693            has_pending_recv = PJ_FALSE; 
     
    682698                (*cb.on_read)(this, read_len); 
    683699            } 
    684         } catch (Exception^ e) { 
     700        } catch (...) { 
    685701            has_pending_recv = PJ_FALSE; 
    686702 
     
    14791495 
    14801496    *newsock = (pj_sock_t)new_uwp_sock; 
    1481     pj_sockaddr_cp(addr, new_uwp_sock->GetRemoteAddr()); 
    1482     *addrlen = pj_sockaddr_get_len(addr); 
     1497 
     1498    if (addr) 
     1499        pj_sockaddr_cp(addr, new_uwp_sock->GetRemoteAddr()); 
     1500 
     1501    if (addrlen) 
     1502        *addrlen = pj_sockaddr_get_len(addr); 
    14831503 
    14841504    return PJ_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.