]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
use threading in testserver and ivrd
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 14 Dec 2011 18:16:09 +0000 (12:16 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 14 Dec 2011 18:16:09 +0000 (12:16 -0600)
libs/esl/ivrd.c
libs/esl/src/esl.c
libs/esl/src/include/esl.h
libs/esl/testserver.c

index 842ef6be1399def9af8fe78a7eed86c7d506d628..406632725766684b6ce9bce2c2a25fdb09358fe0 100644 (file)
@@ -42,11 +42,6 @@ static void mycallback(esl_socket_t server_sock, esl_socket_t client_sock, struc
        char path_buffer[1024] = { 0 };
        const char *path;
        
-       if (fork()) {
-               close(client_sock);
-               return;
-       }
-       
        if (esl_attach_handle(&handle, client_sock, addr) != ESL_SUCCESS || !handle.info_event) {
                esl_log(ESL_LOG_ERROR, "Socket Error\n");
                exit(0);
@@ -95,9 +90,7 @@ int main(int argc, char *argv[])
                return -1;
        }
 
-       signal(SIGCHLD, SIG_IGN);
-
-       esl_listen(ip, port, mycallback);
+       esl_listen(ip, port, mycallback, 100000);
        
        return 0;
 }
index 0c387e79ef50d83d8f4f76ae223ac49e59307f33..01c87fd9e5934a6dcab527626e8f4c2adcaee6d5 100644 (file)
@@ -612,12 +612,31 @@ static int esl_socket_reuseaddr(esl_socket_t socket)
 #endif
 }
 
-ESL_DECLARE(esl_status_t) esl_listen(const char *host, esl_port_t port, esl_listen_callback_t callback)
+struct thread_handler {
+       esl_listen_callback_t callback;
+       int server_sock;
+       int client_sock;
+       struct sockaddr_in addr;
+};
+
+static void *client_thread(esl_thread_t *me, void *obj)
+{
+       struct thread_handler *handler = (struct thread_handler *) obj;
+
+       handler->callback(handler->server_sock, handler->client_sock, &handler->addr);
+       free(handler);
+
+       return NULL;
+
+}
+
+ESL_DECLARE(esl_status_t) esl_listen(const char *host, esl_port_t port, esl_listen_callback_t callback, int max)
 {
        esl_socket_t server_sock = ESL_SOCK_INVALID;
        struct sockaddr_in addr;
        esl_status_t status = ESL_SUCCESS;
-       
+       struct thread_handler *handler = NULL;
+
        if ((server_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
                return ESL_FAIL;
        }
@@ -634,7 +653,7 @@ ESL_DECLARE(esl_status_t) esl_listen(const char *host, esl_port_t port, esl_list
                goto end;
        }
 
-    if (listen(server_sock, 10000) < 0) {
+    if (listen(server_sock, max) < 0) {
                status = ESL_FAIL;
                goto end;
        }
@@ -655,7 +674,14 @@ ESL_DECLARE(esl_status_t) esl_listen(const char *host, esl_port_t port, esl_list
                        goto end;
                }
                
-               callback(server_sock, client_sock, &echoClntAddr);
+               handler = malloc(sizeof(*handler));
+               memset(handler, 0, sizeof(*handler));
+               handler->callback = callback;
+               handler->server_sock = server_sock;
+               handler->client_sock = client_sock;
+               handler->addr = echoClntAddr;
+
+               esl_thread_create_detached(client_thread, handler);
        }
 
  end:
index 74fd2342a559f7817c86e691b9f4bfa18bddb7cc..2f1a50949a6494a2f96c6a7e16d1f5ac48fdfb63 100644 (file)
@@ -391,7 +391,7 @@ ESL_DECLARE(esl_status_t) esl_attach_handle(esl_handle_t *handle, esl_socket_t s
     \param port Port to bind to
     \param callback Callback that will be called upon data received
 */
-ESL_DECLARE(esl_status_t) esl_listen(const char *host, esl_port_t port, esl_listen_callback_t callback);
+ESL_DECLARE(esl_status_t) esl_listen(const char *host, esl_port_t port, esl_listen_callback_t callback, int max);
 /*!
     \brief Executes application with sendmsg to a specific UUID. Used for outbound socket.
     \param handle Handle that the msg will be sent
index 2e398055e55b0048de8dc49b5aec71c916dedb8b..cf60313fe7ef4917b7cb13f2fe657a3c3f07ea79 100644 (file)
@@ -9,11 +9,6 @@ static void mycallback(esl_socket_t server_sock, esl_socket_t client_sock, struc
        esl_status_t status;
        time_t exp = 0;
 
-       if (fork()) {
-               close(client_sock);
-               return;
-       }
-
        esl_attach_handle(&handle, client_sock, addr);
 
        esl_log(ESL_LOG_INFO, "Connected! %d\n", handle.sock);
@@ -53,7 +48,7 @@ static void mycallback(esl_socket_t server_sock, esl_socket_t client_sock, struc
 int main(void)
 {
        esl_global_set_default_logger(7);
-       esl_listen("localhost", 8084, mycallback);
+       esl_listen("localhost", 8084, mycallback, 100000);
        
        return 0;
 }