summaryrefslogtreecommitdiff
path: root/main/http.c
diff options
context:
space:
mode:
authorSean Bright <sean.bright@gmail.com>2017-03-18 13:30:32 -0400
committerSean Bright <sean.bright@gmail.com>2017-03-20 08:51:47 -0400
commit38cebc73a33195fa14d6fa417284c59efe6111ee (patch)
tree187ba2eac60466d82253c8753a4ffc144b14809a /main/http.c
parentbaeabb82eaa92a9d493ae92b77ece72faf37d619 (diff)
thread safety: Don't use getprotobyname()
POSIX does not require getprotobyname() to be thread safe and some implementations use static memory which causes issues when multiple threads are used. Further, our usage of it today is just to ultimately get IPPROTO_TCP for calls to setsockopt(). So instead we just use IPPROTO_TCP directly. Change-Id: I2e14e58674808f7ce99b2f5e900d0f90d0d8da48
Diffstat (limited to 'main/http.c')
-rw-r--r--main/http.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/main/http.c b/main/http.c
index 155b04b78..80c7b3cb4 100644
--- a/main/http.c
+++ b/main/http.c
@@ -1915,8 +1915,7 @@ static int httpd_process_request(struct ast_tcptls_session_instance *ser)
static void *httpd_helper_thread(void *data)
{
struct ast_tcptls_session_instance *ser = data;
- struct protoent *p;
- int flags;
+ int flags = 1;
int timeout;
if (!ser || !ser->f) {
@@ -1936,17 +1935,8 @@ static void *httpd_helper_thread(void *data)
* This is necessary to prevent delays (caused by buffering) as we
* write to the socket in bits and pieces.
*/
- p = getprotobyname("tcp");
- if (p) {
- int arg = 1;
-
- if (setsockopt(ser->fd, p->p_proto, TCP_NODELAY, (char *) &arg, sizeof(arg) ) < 0) {
- ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno));
- ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n");
- }
- } else {
- ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection, getprotobyname(\"tcp\") failed\n");
- ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n");
+ if (setsockopt(ser->fd, IPPROTO_TCP, TCP_NODELAY, (char *) &flags, sizeof(flags)) < 0) {
+ ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno));
}
/* make sure socket is non-blocking */