Ignore:
Timestamp:
Nov 9, 2005 3:37:19 PM (19 years ago)
Author:
bennylp
Message:

Rework pjlib++

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/main/pjlib/src/pj/ioqueue_common_abs.c

    r35 r36  
    229229        if (h->fd_type == PJ_SOCK_DGRAM) { 
    230230            pj_list_erase(write_op); 
     231            write_op->op = 0; 
     232 
    231233            if (pj_list_empty(&h->write_list)) 
    232234                ioqueue_remove_from_set(ioqueue, h->fd, WRITEABLE_EVENT); 
     
    269271                /* Write completion of the whole stream. */ 
    270272                pj_list_erase(write_op); 
     273                write_op->op = 0; 
    271274 
    272275                /* Clear operation if there's no more data to send. */ 
     
    315318        accept_op = h->accept_list.next; 
    316319        pj_list_erase(accept_op); 
     320        accept_op->op = 0; 
    317321 
    318322        /* Clear bit in fdset if there is no more pending accept */ 
     
    348352        read_op = h->read_list.next; 
    349353        pj_list_erase(read_op); 
     354        read_op->op = 0; 
    350355 
    351356        /* Clear fdset if there is no pending read. */ 
     
    477482    PJ_CHECK_STACK(); 
    478483 
     484    read_op = (struct read_operation*)op_key; 
     485    read_op->op = 0; 
     486 
    479487    /* Try to see if there's data immediately available.  
    480488     */ 
     
    497505     * Must schedule asynchronous operation to the ioqueue. 
    498506     */ 
    499     read_op = (struct read_operation*)op_key; 
    500  
    501507    read_op->op = PJ_IOQUEUE_OP_RECV; 
    502508    read_op->buf = buffer; 
     
    531537    PJ_ASSERT_RETURN(key && op_key && buffer && length, PJ_EINVAL); 
    532538    PJ_CHECK_STACK(); 
     539 
     540    read_op = (struct read_operation*)op_key; 
     541    read_op->op = 0; 
    533542 
    534543    /* Try to see if there's data immediately available.  
     
    553562     * Must schedule asynchronous operation to the ioqueue. 
    554563     */ 
    555     read_op = (struct read_operation*)op_key; 
    556  
    557564    read_op->op = PJ_IOQUEUE_OP_RECV_FROM; 
    558565    read_op->buf = buffer; 
     
    587594    PJ_ASSERT_RETURN(key && op_key && data && length, PJ_EINVAL); 
    588595    PJ_CHECK_STACK(); 
     596 
     597    write_op = (struct write_operation*)op_key; 
     598    write_op->op = 0; 
    589599 
    590600    /* Fast track: 
     
    625635     * Schedule asynchronous send. 
    626636     */ 
    627     write_op = (struct write_operation*)op_key; 
    628637    write_op->op = PJ_IOQUEUE_OP_SEND; 
    629638    write_op->buf = (void*)data; 
     
    660669    PJ_ASSERT_RETURN(key && op_key && data && length, PJ_EINVAL); 
    661670    PJ_CHECK_STACK(); 
     671 
     672    write_op = (struct write_operation*)op_key; 
     673    write_op->op = 0; 
    662674 
    663675    /* Fast track: 
     
    703715     * Schedule asynchronous send. 
    704716     */ 
    705     write_op = (struct write_operation*)op_key; 
    706717    write_op->op = PJ_IOQUEUE_OP_SEND_TO; 
    707718    write_op->buf = (void*)data; 
     
    736747    /* check parameters. All must be specified! */ 
    737748    PJ_ASSERT_RETURN(key && op_key && new_sock, PJ_EINVAL); 
     749 
     750    accept_op = (struct accept_operation*)op_key; 
     751    accept_op->op = 0; 
    738752 
    739753    /* Fast track: 
     
    768782     * connection available. 
    769783     */ 
    770     accept_op = (struct accept_operation*)op_key; 
    771  
    772784    accept_op->op = PJ_IOQUEUE_OP_ACCEPT; 
    773785    accept_op->accept_fd = new_sock; 
     
    822834#endif  /* PJ_HAS_TCP */ 
    823835 
     836/* 
     837 * pj_ioqueue_is_pending() 
     838 */ 
     839PJ_DEF(pj_bool_t) pj_ioqueue_is_pending( pj_ioqueue_key_t *key, 
     840                                         pj_ioqueue_op_key_t *op_key ) 
     841{ 
     842    struct generic_operation *op_rec; 
     843 
     844    PJ_UNUSED_ARG(key); 
     845 
     846    op_rec = (struct generic_operation*)op_key; 
     847    return op_rec->op != 0; 
     848} 
     849 
     850 
     851/* 
     852 * pj_ioqueue_post_completion() 
     853 */ 
     854PJ_DEF(pj_status_t) pj_ioqueue_post_completion( pj_ioqueue_key_t *key, 
     855                                                pj_ioqueue_op_key_t *op_key, 
     856                                                pj_ssize_t bytes_status ) 
     857{ 
     858    struct generic_operation *op_rec; 
     859 
     860    /* 
     861     * Find the operation key in all pending operation list to 
     862     * really make sure that it's still there; then call the callback. 
     863     */ 
     864    pj_mutex_lock(key->mutex); 
     865 
     866    /* Find the operation in the pending read list. */ 
     867    op_rec = (struct generic_operation*)key->read_list.next; 
     868    while (op_rec != (void*)&key->read_list) { 
     869        if (op_rec == (void*)op_key) { 
     870            pj_list_erase(op_rec); 
     871            op_rec->op = 0; 
     872            pj_mutex_unlock(key->mutex); 
     873 
     874            (*key->cb.on_read_complete)(key, op_key, bytes_status); 
     875            return PJ_SUCCESS; 
     876        } 
     877        op_rec = op_rec->next; 
     878    } 
     879 
     880    /* Find the operation in the pending write list. */ 
     881    op_rec = (struct generic_operation*)key->write_list.next; 
     882    while (op_rec != (void*)&key->write_list) { 
     883        if (op_rec == (void*)op_key) { 
     884            pj_list_erase(op_rec); 
     885            op_rec->op = 0; 
     886            pj_mutex_unlock(key->mutex); 
     887 
     888            (*key->cb.on_write_complete)(key, op_key, bytes_status); 
     889            return PJ_SUCCESS; 
     890        } 
     891        op_rec = op_rec->next; 
     892    } 
     893 
     894    /* Find the operation in the pending accept list. */ 
     895    op_rec = (struct generic_operation*)key->accept_list.next; 
     896    while (op_rec != (void*)&key->accept_list) { 
     897        if (op_rec == (void*)op_key) { 
     898            pj_list_erase(op_rec); 
     899            op_rec->op = 0; 
     900            pj_mutex_unlock(key->mutex); 
     901 
     902            (*key->cb.on_accept_complete)(key, op_key,  
     903                                          PJ_INVALID_SOCKET, 
     904                                          bytes_status); 
     905            return PJ_SUCCESS; 
     906        } 
     907        op_rec = op_rec->next; 
     908    } 
     909 
     910    pj_mutex_unlock(key->mutex); 
     911     
     912    return PJ_EINVALIDOP; 
     913} 
     914 
Note: See TracChangeset for help on using the changeset viewer.