]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Use non-blocking socket() and pipe() wrappers
authorSean Bright <sean.bright@gmail.com>
Tue, 11 Dec 2018 14:54:43 +0000 (09:54 -0500)
committerSean Bright <sean.bright@gmail.com>
Tue, 11 Dec 2018 17:28:35 +0000 (12:28 -0500)
Change-Id: I050ceffe5a133d5add2dab46687209813d58f597

main/tcptls.c
main/udptl.c
res/res_agi.c
res/res_rtp_asterisk.c
res/res_timing_pthread.c

index 3ba52ff6a3b17c7afa2028579823a1d93623c411..7930c5002b1b784ee7edf6712a96641a22e8939d 100644 (file)
@@ -746,7 +746,7 @@ void ast_tcptls_server_start(struct ast_tcptls_session_args *desc)
                return;
        }
 
-       desc->accept_fd = socket(ast_sockaddr_is_ipv6(&desc->local_address) ?
+       desc->accept_fd = ast_socket_nonblock(ast_sockaddr_is_ipv6(&desc->local_address) ?
                                 AF_INET6 : AF_INET, SOCK_STREAM, 0);
        if (desc->accept_fd < 0) {
                ast_log(LOG_ERROR, "Unable to allocate socket for %s: %s\n", desc->name, strerror(errno));
@@ -767,7 +767,6 @@ void ast_tcptls_server_start(struct ast_tcptls_session_args *desc)
        }
 
 systemd_socket_activation:
-       ast_fd_set_flags(desc->accept_fd, O_NONBLOCK);
        if (ast_pthread_create_background(&desc->master, NULL, desc->accept_fn, desc)) {
                ast_log(LOG_ERROR, "Unable to launch thread for %s on %s: %s\n",
                        desc->name,
index 7349d6aa4cd85f55f3caa072a8d2ec7bab78de62..99a9c74149d69aebd7195f9ff41db109f6addf26 100644 (file)
@@ -1037,13 +1037,12 @@ struct ast_udptl *ast_udptl_new_with_bindaddr(struct ast_sched_context *sched, s
                udptl->tx[i].buf_len = -1;
        }
 
-       if ((udptl->fd = socket(ast_sockaddr_is_ipv6(addr) ?
+       if ((udptl->fd = ast_socket_nonblock(ast_sockaddr_is_ipv6(addr) ?
                                        AF_INET6 : AF_INET, SOCK_DGRAM, 0)) < 0) {
                ast_free(udptl);
                ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
                return NULL;
        }
-       ast_fd_set_flags(udptl->fd, O_NONBLOCK);
 
 #ifdef SO_NO_CHECK
        if (cfg->general->nochecksums)
index 0931c1a0727a760e050715680120c610ed7ec58d..d88d5118b93f5371879f6cb365f893e3962f6aa9 100644 (file)
@@ -2071,16 +2071,11 @@ static enum agi_result launch_netscript(char *agiurl, char *argv[], int *fds)
                        ast_sockaddr_set_port(&addrs[i], AGI_PORT);
                }
 
-               if ((s = socket(addrs[i].ss.ss_family, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+               if ((s = ast_socket_nonblock(addrs[i].ss.ss_family, SOCK_STREAM, IPPROTO_TCP)) < 0) {
                        ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
                        continue;
                }
 
-               if (ast_fd_set_flags(s, O_NONBLOCK)) {
-                       close(s);
-                       continue;
-               }
-
                if (ast_connect(s, &addrs[i]) && errno == EINPROGRESS) {
 
                        if (handle_connection(agiurl, addrs[i], s)) {
index c2299bc9e42d8a5c49ee135a15b13f641ae522f1..605d69b4626f5b06c1c6c8b96f379bbcce8dba5f 100644 (file)
@@ -3112,21 +3112,18 @@ static double stddev_compute(double stddev, double sample, double normdev, doubl
 
 static int create_new_socket(const char *type, int af)
 {
-       int sock = socket(af, SOCK_DGRAM, 0);
+       int sock = ast_socket_nonblock(af, SOCK_DGRAM, 0);
 
        if (sock < 0) {
-               if (!type) {
-                       type = "RTP/RTCP";
-               }
                ast_log(LOG_WARNING, "Unable to allocate %s socket: %s\n", type, strerror(errno));
-       } else {
-               ast_fd_set_flags(sock, O_NONBLOCK);
+               return sock;
+       }
+
 #ifdef SO_NO_CHECK
-               if (nochecksums) {
-                       setsockopt(sock, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
-               }
-#endif
+       if (nochecksums) {
+               setsockopt(sock, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
        }
+#endif
 
        return sock;
 }
index c1015798104d42f9f45d4e984d52223d8f4d21f7..3ca7e5c28e90e59f26dddde42cdf6517b2f65aab 100644 (file)
@@ -114,7 +114,6 @@ static struct {
 static void *pthread_timer_open(void)
 {
        struct pthread_timer *timer;
-       int i;
 
        if (!(timer = ao2_alloc(sizeof(*timer), pthread_timer_destructor))) {
                errno = ENOMEM;
@@ -124,15 +123,11 @@ static void *pthread_timer_open(void)
        timer->pipe[PIPE_READ] = timer->pipe[PIPE_WRITE] = -1;
        timer->state = TIMER_STATE_IDLE;
 
-       if (pipe(timer->pipe)) {
+       if (ast_pipe_nonblock(timer->pipe)) {
                ao2_ref(timer, -1);
                return NULL;
        }
 
-       for (i = 0; i < ARRAY_LEN(timer->pipe); ++i) {
-               ast_fd_set_flags(timer->pipe[i], O_NONBLOCK);
-       }
-
        ao2_lock(pthread_timers);
        if (!ao2_container_count(pthread_timers)) {
                ast_mutex_lock(&timing_thread.lock);