summaryrefslogtreecommitdiff
path: root/main/tcptls.c
diff options
context:
space:
mode:
authorSean Bright <sean.bright@gmail.com>2017-12-07 10:52:39 -0500
committerSean Bright <sean.bright@gmail.com>2017-12-08 13:28:04 -0600
commit2ffe52a116ad05d060cbedda93c48cf5a4415ca3 (patch)
tree9f8d99288f532ad213b8681e7616c26e8535df24 /main/tcptls.c
parentb0b28446c1e5f76c54b823bc3f4e2a5423c9c79b (diff)
utils: Add convenience function for setting fd flags
There are many places in the code base where we ignore the return value of fcntl() when getting/setting file descriptior flags. This patch introduces a convenience function that allows setting or clearing file descriptor flags and will also log an error on failure for later analysis. Change-Id: I8b81901e1b1bd537ca632567cdb408931c6eded7
Diffstat (limited to 'main/tcptls.c')
-rw-r--r--main/tcptls.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/main/tcptls.c b/main/tcptls.c
index a6d0538af..02a2af5c6 100644
--- a/main/tcptls.c
+++ b/main/tcptls.c
@@ -223,7 +223,7 @@ void *ast_tcptls_server_root(void *data)
pthread_t launched;
for (;;) {
- int i, flags;
+ int i;
if (desc->periodic_fn) {
desc->periodic_fn(desc);
@@ -261,8 +261,7 @@ void *ast_tcptls_server_root(void *data)
close(fd);
continue;
}
- flags = fcntl(fd, F_GETFL);
- fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
+ ast_fd_clear_flags(fd, O_NONBLOCK);
tcptls_session->stream = ast_iostream_from_fd(&fd);
if (!tcptls_session->stream) {
@@ -514,7 +513,6 @@ void ast_ssl_teardown(struct ast_tls_config *cfg)
struct ast_tcptls_session_instance *ast_tcptls_client_start(struct ast_tcptls_session_instance *tcptls_session)
{
struct ast_tcptls_session_args *desc;
- int flags;
if (!(desc = tcptls_session->parent)) {
goto client_start_error;
@@ -528,8 +526,7 @@ struct ast_tcptls_session_instance *ast_tcptls_client_start(struct ast_tcptls_se
goto client_start_error;
}
- flags = fcntl(desc->accept_fd, F_GETFL);
- fcntl(desc->accept_fd, F_SETFL, flags & ~O_NONBLOCK);
+ ast_fd_clear_flags(desc->accept_fd, O_NONBLOCK);
if (desc->tls_cfg) {
desc->tls_cfg->enabled = 1;
@@ -621,7 +618,6 @@ error:
void ast_tcptls_server_start(struct ast_tcptls_session_args *desc)
{
- int flags;
int x = 1;
int tls_changed = 0;
int sd_socket;
@@ -740,8 +736,7 @@ void ast_tcptls_server_start(struct ast_tcptls_session_args *desc)
}
systemd_socket_activation:
- flags = fcntl(desc->accept_fd, F_GETFL);
- fcntl(desc->accept_fd, F_SETFL, flags | O_NONBLOCK);
+ 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,