Re: [PATCH] PJSIP: Don't sleep after error in pj_ioqueue_poll().

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

 



Hi Kal,

We're thinking to reduce the delay to max 10 ms instead of removing it
completely. This should allow for error recovery. Please let us know
your opinion/feedback. Patch attached.

Regards,
Ming

On Wed, Sep 27, 2017 at 4:00 AM, b17 c0de <b17c0de@xxxxxxxxx> wrote:
> Hi PJ peeps,
> Please apply this patch which removes the pj_thread_sleep() call from
> pjsip_endpt_handle_events2(). I think it makes more sense just to
> return the error to the user immediately and let them decide if they
> want to sleep (like pjsua-lib does).
>
> One concrete case when this sleep is problematic is when a signal
> occurs. In this case, the call to pj_ioqueue_poll() will return
> because of EINTR which will cause the main loop to additionally sleep
> for the full timeout. This means, if pjsip_endpt_handle_events2() is
> called with a large timeout, the signal/interrupt will block the app
> for the full timeout interval if a signal happens. This is a problem.
>
> Thanks,
> Kal
>
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
>
> pjsip mailing list
> pjsip@xxxxxxxxxxxxxxx
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>
Index: pjsip/src/pjsip/sip_endpoint.c
===================================================================
--- pjsip/src/pjsip/sip_endpoint.c	(revision 5663)
+++ pjsip/src/pjsip/sip_endpoint.c	(working copy)
@@ -34,6 +34,7 @@
 #include <pj/assert.h>
 #include <pj/errno.h>
 #include <pj/lock.h>
+#include <pj/math.h>
 
 #define PJSIP_EX_NO_MEMORY  pj_NO_MEMORY_EXCEPTION()
 #define THIS_FILE	    "sip_endpoint.c"
@@ -699,6 +700,7 @@
 					       const pj_time_val *max_timeout,
 					       unsigned *p_count)
 {
+    enum { MAX_TIMEOUT_ON_ERR = 10 };
     /* timeout is 'out' var. This just to make compiler happy. */
     pj_time_val timeout = { 0, 0};
     unsigned count = 0, net_event_count = 0;
@@ -741,8 +743,9 @@
     do {
 	c = pj_ioqueue_poll( endpt->ioqueue, &timeout);
 	if (c < 0) {
+	    unsigned msec = PJ_TIME_VAL_MSEC(timeout);
 	    pj_status_t err = pj_get_netos_error();
-	    pj_thread_sleep(PJ_TIME_VAL_MSEC(timeout));
+	    pj_thread_sleep(PJ_MIN(msec, MAX_TIMEOUT_ON_ERR));
 	    if (p_count)
 		*p_count = count;
 	    return err;
_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[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