bug (or feature?) in pj_ioqueue_poll()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Benny!

Trying to find out the cause of the strange "meditative" behaviour of my pjsip-test application, I caught the "time killer" in function pjsip_endpt_handle_events2()

	c = pj_ioqueue_poll( endpt->ioqueue, &timeout);
	if (c < 0) {
        pj_thread_sleep(PJ_TIME_VAL_MSEC(timeout));

and its "accomplice" in function pj_ioqueue_poll()

    count = pj_sock_select(ioqueue->nfds+1, &rfdset, &wfdset, &xfdset, timeout);
    if (count <= 0)
        return -pj_get_netos_error();

I don't understand, why timeout expiration of select() (with zero return value) must lead to errno-based (in Linux case) return value of pj_ioqueue_poll(), and possible consequent pj_thread_sleep() with 'timeout' value (for the second time)? 
"Functions do not change errno when they succeed; thus, the value of errno after a successful call is not necessarily zero" [http://www.gnu.org/software/libc/manual/html_node/Checking-for-Errors.html].

For test purposes I've modified the latter code to

    count = pj_sock_select(ioqueue->nfds+1, &rfdset, &wfdset, &xfdset, timeout);
    PJ_LOG(5, ("</sock_select>", "c=%d, t=%d.%03d; Err=%d", 
        count, timeout->sec, timeout->msec, pj_get_netos_error() ));
    if (count == 0)
        return count;
    else if (count < 0)
        return -pj_get_netos_error();

and I've got (on Linux 2.6.17, gcc 4.0.2, glibc 2.3.6):
    
 10:58:55.177 </sock_select> c=1, t=26.557; Err=0
 10:58:55.194 </sock_select> c=1, t=0.499; Err=0
 10:58:55.200 </sock_select> c=1, t=0.500; Err=120011
 10:58:55.201 </sock_select> c=1, t=4.810; Err=120011
 10:59:00.012 </sock_select> c=0, t=4.809; Err=120011
 10:59:27.198 </sock_select> c=0, t=27.183; Err=120011
 10:59:27.202 </sock_select> c=0, t=0.002; Err=120011
 11:00:00.012 </sock_select> c=0, t=32.808; Err=120011
 . . . . .
In all cases of c=0 the original code would result in unreasonable pj_thread_sleep().

Best regards,
Sergey




[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux