Fix: Polling of file descriptors
authorAndreas Eversberg <jolly@eversberg.eu>
Tue, 21 Aug 2012 06:23:19 +0000 (08:23 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sun, 16 Dec 2012 09:11:46 +0000 (10:11 +0100)
It is only done when enabled by config or when any SIP interface is
created.

Thanx to Wimpy for catching this bug.

main.c
sip.cpp
sip.h

diff --git a/main.c b/main.c
index 140fc50..35b972f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -187,7 +187,6 @@ int main(int argc, char *argv[])
 #endif
        char                    tracetext[256], lock[128];
        char                    options_error[256];
-       int                     polling = 0;
 
 #if 0
        /* init fdset */
@@ -270,7 +269,6 @@ int main(int argc, char *argv[])
                PERROR("%s", options_error);
                goto free;
        }
-       polling = options.polling;
 
 #ifdef WITH_MISDN
        /* init mISDN */
@@ -372,7 +370,6 @@ int main(int argc, char *argv[])
 #ifdef WITH_SIP
        /* init SIP globals */
        sip_init();
-       polling = 1; /* must poll, because of SIP events */
 #endif
 
 #ifdef WITH_SS5
@@ -492,7 +489,11 @@ init is done when interface is up
                        usleep(10000);
                }
 #else
+#ifdef WITH_SIP
+               if (options.polling || any_sip_interface) {
+#else
                if (options.polling) {
+#endif
                        if (!select_main(1, NULL, NULL, NULL)) {
 #ifdef WITH_SIP
                                /* FIXME: check if work was done */
diff --git a/sip.cpp b/sip.cpp
index 9081824..4def0a1 100644 (file)
--- a/sip.cpp
+++ b/sip.cpp
@@ -19,6 +19,8 @@
 
 unsigned char flip[256];
 
+int any_sip_interface = 0;
+
 //pthread_mutex_t mutex_msg;
 su_home_t      sip_home[1];
 
@@ -1890,6 +1892,8 @@ int sip_init_inst(struct interface *interface)
 
        PDEBUG(DEBUG_SIP, "SIP interface created (inst=%p)\n", inst);
 
+       any_sip_interface = 1;
+
        return 0;
 }
 
@@ -1908,6 +1912,16 @@ void sip_exit_inst(struct interface *interface)
        interface->sip_inst = NULL;
 
        PDEBUG(DEBUG_SIP, "SIP interface removed\n");
+
+       /* check if there is any other SIP interface left */
+       interface = interface_first;
+       while (interface) {
+               if (interface->sip_inst)
+                       break;
+               interface = interface->next;
+       }
+       if (!interface)
+               any_sip_interface = 0;
 }
 
 extern su_log_t su_log_default[];
diff --git a/sip.h b/sip.h
index dbb311c..77fb9fc 100644 (file)
--- a/sip.h
+++ b/sip.h
@@ -11,6 +11,8 @@
 
 #include <sofia-sip/nua.h>
 
+extern int any_sip_interface;
+
 /* SIP port class */
 class Psip : public Port
 {