Ignore:
Timestamp:
Feb 21, 2013 11:18:36 AM (11 years ago)
Author:
bennylp
Message:

Fixed #1616: Implementation of Group lock and other foundation in PJLIB for fixing synchronization issues

File:
1 edited

Legend:

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

    r3553 r4359  
    4444}; 
    4545 
     46enum shutdown_dir 
     47{ 
     48    SHUT_NONE = 0, 
     49    SHUT_RX = 1, 
     50    SHUT_TX = 2 
     51}; 
     52 
    4653struct read_op 
    4754{ 
     
    7885    void                *user_data; 
    7986    unsigned             async_count; 
     87    unsigned             shutdown; 
    8088    unsigned             max_loop; 
    8189    pj_activesock_cb     cb; 
     
    210218#endif 
    211219 
    212     status = pj_ioqueue_register_sock(pool, ioqueue, sock, asock,  
    213                                       &ioq_cb, &asock->key); 
     220    status = pj_ioqueue_register_sock2(pool, ioqueue, sock, 
     221                                       (opt? opt->grp_lock : NULL), 
     222                                       asock, &ioq_cb, &asock->key); 
    214223    if (status != PJ_SUCCESS) { 
    215224        pj_activesock_close(asock); 
     
    284293} 
    285294 
    286  
    287295PJ_DEF(pj_status_t) pj_activesock_close(pj_activesock_t *asock) 
    288296{ 
    289297    PJ_ASSERT_RETURN(asock, PJ_EINVAL); 
     298    asock->shutdown = SHUT_RX | SHUT_TX; 
    290299    if (asock->key) { 
    291300#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \ 
     
    448457 
    449458    asock = (pj_activesock_t*) pj_ioqueue_get_user_data(key); 
     459 
     460    /* Ignore if we've been shutdown */ 
     461    if (asock->shutdown & SHUT_RX) 
     462        return; 
    450463 
    451464    do { 
     
    570583                return; 
    571584 
     585            /* Also stop further read if we've been shutdown */ 
     586            if (asock->shutdown & SHUT_RX) 
     587                return; 
     588 
    572589            /* Only stream oriented socket may leave data in the packet */ 
    573590            if (asock->stream_oriented) { 
     
    649666    PJ_ASSERT_RETURN(asock && send_key && data && size, PJ_EINVAL); 
    650667 
     668    if (asock->shutdown & SHUT_TX) 
     669        return PJ_EINVALIDOP; 
     670 
    651671    send_key->activesock_data = NULL; 
    652672 
     
    699719                     PJ_EINVAL); 
    700720 
     721    if (asock->shutdown & SHUT_TX) 
     722        return PJ_EINVALIDOP; 
     723 
    701724    return pj_ioqueue_sendto(asock->key, send_key, data, size, flags, 
    702725                             addr, addr_len); 
     
    711734 
    712735    asock = (pj_activesock_t*) pj_ioqueue_get_user_data(key); 
     736 
     737    /* Ignore if we've been shutdown. This may cause data to be partially 
     738     * sent even when 'wholedata' was requested if the OS only sent partial 
     739     * buffer. 
     740     */ 
     741    if (asock->shutdown & SHUT_TX) 
     742        return; 
    713743 
    714744    if (bytes_sent > 0 && op_key->activesock_data) { 
     
    756786    PJ_ASSERT_RETURN(asock, PJ_EINVAL); 
    757787    PJ_ASSERT_RETURN(asock->accept_op==NULL, PJ_EINVALIDOP); 
     788 
     789    /* Ignore if we've been shutdown */ 
     790    if (asock->shutdown) 
     791        return PJ_EINVALIDOP; 
    758792 
    759793    asock->accept_op = (struct accept_op*) 
     
    798832 
    799833    PJ_UNUSED_ARG(new_sock); 
     834 
     835    /* Ignore if we've been shutdown */ 
     836    if (asock->shutdown) 
     837        return; 
    800838 
    801839    do { 
     
    836874        } 
    837875 
     876        /* Don't start another accept() if we've been shutdown */ 
     877        if (asock->shutdown) 
     878            return; 
     879 
    838880        /* Prepare next accept() */ 
    839881        accept_op->new_sock = PJ_INVALID_SOCKET; 
     
    854896{ 
    855897    PJ_UNUSED_ARG(pool); 
     898 
     899    if (asock->shutdown) 
     900        return PJ_EINVALIDOP; 
     901 
    856902    return pj_ioqueue_connect(asock->key, remaddr, addr_len); 
    857903} 
     
    861907{ 
    862908    pj_activesock_t *asock = (pj_activesock_t*) pj_ioqueue_get_user_data(key); 
     909 
     910    /* Ignore if we've been shutdown */ 
     911    if (asock->shutdown) 
     912        return; 
    863913 
    864914    if (asock->cb.on_connect_complete) { 
Note: See TracChangeset for help on using the changeset viewer.