On 3/13/08, Sergey Bakulin <serbah at mail.ru> wrote: > 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(). Hi Sergey, frankly I totally forgot why it was done that way. All I can read from the change log is this change was done in r126 more than two years ago, and it was done as part of huge patch to support WinCE (which doesn't make sense!). But your explanation sounds correct, and I think I agree with you. I've just fixed this in http://trac.pjsip.org/repos/ticket/512 thanks, -benny > Best regards, > Sergey > > > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip at lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org >