Ignore:
Timestamp:
Jul 10, 2006 9:30:34 PM (18 years ago)
Author:
bennylp
Message:

Do several ioqueue poll in one go in pjsip_endpoint, because IOCP can only report one event at a time

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c

    r596 r598  
    608608    /* timeout is 'out' var. This just to make compiler happy. */ 
    609609    pj_time_val timeout = { 0, 0}; 
    610     unsigned count = 0; 
     610    unsigned count = 0, net_event_count = 0; 
    611611    int c; 
    612612 
     
    633633    } 
    634634 
    635     /* Poll ioqueue. */ 
    636     c = pj_ioqueue_poll( endpt->ioqueue, &timeout); 
    637     if (c < 0) { 
    638         pj_thread_sleep(1); 
    639         if (p_count) 
    640             *p_count = count; 
    641         return pj_get_netos_error(); 
    642     } else { 
    643         count += c; 
    644         if (p_count) 
    645             *p_count = count; 
    646         return PJ_SUCCESS; 
    647     } 
     635    /* Poll ioqueue.  
     636     * Repeat polling the ioqueue while we have immediate events, because 
     637     * timer heap may process more than one events, so if we only process 
     638     * one network events at a time (such as when IOCP backend is used), 
     639     * the ioqueue may have trouble keeping up with the request rate. 
     640     * 
     641     * For example, for each send() request, one network event will be 
     642     *   reported by ioqueue for the send() completion. If we don't poll 
     643     *   the ioqueue often enough, the send() completion will not be 
     644     *   reported in timely manner. 
     645     */ 
     646    do { 
     647        c = pj_ioqueue_poll( endpt->ioqueue, &timeout); 
     648        if (c < 0) { 
     649            pj_thread_sleep(PJ_TIME_VAL_MSEC(timeout)); 
     650            if (p_count) 
     651                *p_count = count; 
     652            return pj_get_netos_error(); 
     653        } else if (c == 0) { 
     654            break; 
     655        } else { 
     656            net_event_count += c; 
     657            timeout.sec = timeout.msec = 0; 
     658        } 
     659    } while (c > 0 && net_event_count < PJSIP_MAX_TIMED_OUT_ENTRIES*2); 
     660 
     661    count += net_event_count; 
     662    if (p_count) 
     663        *p_count = count; 
     664 
     665    return PJ_SUCCESS; 
    648666} 
    649667 
Note: See TracChangeset for help on using the changeset viewer.