aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r--src/microhttpd/daemon.c81
1 files changed, 35 insertions, 46 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 4ab43f9d..2bbb7b2a 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -728,7 +728,7 @@ MHD_handle_connection (void *data)
728 /* how did we get here!? */ 728 /* how did we get here!? */
729 goto exit; 729 goto exit;
730 } 730 }
731 num_ready = SELECT (max + 1, &rs, &ws, NULL, tvp); 731 num_ready = MHD_SYS_select_ (max + 1, &rs, &ws, NULL, tvp);
732 if (num_ready < 0) 732 if (num_ready < 0)
733 { 733 {
734 if (EINTR == MHD_socket_errno_) 734 if (EINTR == MHD_socket_errno_)
@@ -1306,8 +1306,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
1306 } 1306 }
1307 else 1307 else
1308 if ( (MHD_YES == external_add) && 1308 if ( (MHD_YES == external_add) &&
1309 (-1 != daemon->wpipe[1]) && 1309 (MHD_INVALID_PIPE_ != daemon->wpipe[1]) &&
1310 (1 != WRITE (daemon->wpipe[1], "n", 1)) ) 1310 (1 != MHD_pipe_write_ (daemon->wpipe[1], "n", 1)) )
1311 { 1311 {
1312#if HAVE_MESSAGES 1312#if HAVE_MESSAGES
1313 MHD_DLOG (daemon, 1313 MHD_DLOG (daemon,
@@ -1477,8 +1477,8 @@ MHD_resume_connection (struct MHD_Connection *connection)
1477 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 1477 MHD_PANIC ("Failed to acquire cleanup mutex\n");
1478 connection->resuming = MHD_YES; 1478 connection->resuming = MHD_YES;
1479 daemon->resuming = MHD_YES; 1479 daemon->resuming = MHD_YES;
1480 if ( (-1 != daemon->wpipe[1]) && 1480 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[1]) &&
1481 (1 != WRITE (daemon->wpipe[1], "r", 1)) ) 1481 (1 != MHD_pipe_write_ (daemon->wpipe[1], "r", 1)) )
1482 { 1482 {
1483#if HAVE_MESSAGES 1483#if HAVE_MESSAGES
1484 MHD_DLOG (daemon, 1484 MHD_DLOG (daemon,
@@ -1963,9 +1963,9 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
1963 (FD_ISSET (ds, read_fd_set)) ) 1963 (FD_ISSET (ds, read_fd_set)) )
1964 (void) MHD_accept_connection (daemon); 1964 (void) MHD_accept_connection (daemon);
1965 /* drain signaling pipe to avoid spinning select */ 1965 /* drain signaling pipe to avoid spinning select */
1966 if ( (-1 != daemon->wpipe[0]) && 1966 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
1967 (FD_ISSET (daemon->wpipe[0], read_fd_set)) ) 1967 (FD_ISSET (daemon->wpipe[0], read_fd_set)) )
1968 (void) read (daemon->wpipe[0], &tmp, sizeof (tmp)); 1968 (void) MHD_pipe_read_ (daemon->wpipe[0], &tmp, sizeof (tmp));
1969 1969
1970 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 1970 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1971 { 1971 {
@@ -2064,7 +2064,7 @@ MHD_select (struct MHD_Daemon *daemon,
2064 FD_SET (daemon->socket_fd, &rs); 2064 FD_SET (daemon->socket_fd, &rs);
2065 } 2065 }
2066 } 2066 }
2067 if (-1 != daemon->wpipe[0]) 2067 if (MHD_INVALID_PIPE_ != daemon->wpipe[0])
2068 { 2068 {
2069 FD_SET (daemon->wpipe[0], &rs); 2069 FD_SET (daemon->wpipe[0], &rs);
2070 /* update max file descriptor */ 2070 /* update max file descriptor */
@@ -2089,7 +2089,7 @@ MHD_select (struct MHD_Daemon *daemon,
2089 } 2089 }
2090 if (MHD_INVALID_SOCKET == max) 2090 if (MHD_INVALID_SOCKET == max)
2091 return MHD_YES; 2091 return MHD_YES;
2092 num_ready = SELECT (max + 1, &rs, &ws, &es, tv); 2092 num_ready = MHD_SYS_select_ (max + 1, &rs, &ws, &es, tv);
2093 if (MHD_YES == daemon->shutdown) 2093 if (MHD_YES == daemon->shutdown)
2094 return MHD_NO; 2094 return MHD_NO;
2095 if (num_ready < 0) 2095 if (num_ready < 0)
@@ -2150,7 +2150,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
2150 poll_listen = (int) poll_server; 2150 poll_listen = (int) poll_server;
2151 poll_server++; 2151 poll_server++;
2152 } 2152 }
2153 if (-1 != daemon->wpipe[0]) 2153 if (MHD_INVALID_PIPE_ != daemon->wpipe[0])
2154 { 2154 {
2155 p[poll_server].fd = daemon->wpipe[0]; 2155 p[poll_server].fd = daemon->wpipe[0];
2156 p[poll_server].events = POLLIN; 2156 p[poll_server].events = POLLIN;
@@ -2284,7 +2284,7 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon,
2284 poll_listen = poll_count; 2284 poll_listen = poll_count;
2285 poll_count++; 2285 poll_count++;
2286 } 2286 }
2287 if (-1 != daemon->wpipe[0]) 2287 if (MHD_INVALID_PIPE_ != daemon->wpipe[0])
2288 { 2288 {
2289 p[poll_count].fd = daemon->wpipe[0]; 2289 p[poll_count].fd = daemon->wpipe[0];
2290 p[poll_count].events = POLLIN; 2290 p[poll_count].events = POLLIN;
@@ -2456,10 +2456,10 @@ MHD_epoll (struct MHD_Daemon *daemon,
2456 { 2456 {
2457 if (NULL == events[i].data.ptr) 2457 if (NULL == events[i].data.ptr)
2458 continue; /* shutdown signal! */ 2458 continue; /* shutdown signal! */
2459 if ( (-1 != daemon->wpipe[0]) && 2459 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
2460 (daemon->wpipe[0] == events[i].data.fd) ) 2460 (daemon->wpipe[0] == events[i].data.fd) )
2461 { 2461 {
2462 (void) read (daemon->wpipe[0], &tmp, sizeof (tmp)); 2462 (void) MHD_pipe_read_ (daemon->wpipe[0], &tmp, sizeof (tmp));
2463 continue; 2463 continue;
2464 } 2464 }
2465 if (daemon != events[i].data.ptr) 2465 if (daemon != events[i].data.ptr)
@@ -2692,7 +2692,7 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
2692 ret = daemon->socket_fd; 2692 ret = daemon->socket_fd;
2693 if (MHD_INVALID_SOCKET == ret) 2693 if (MHD_INVALID_SOCKET == ret)
2694 return MHD_INVALID_SOCKET; 2694 return MHD_INVALID_SOCKET;
2695 if ( (-1 == daemon->wpipe[1]) && 2695 if ( (MHD_INVALID_PIPE_ == daemon->wpipe[1]) &&
2696 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) 2696 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) )
2697 { 2697 {
2698#if HAVE_MESSAGES 2698#if HAVE_MESSAGES
@@ -3140,7 +3140,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
3140#endif 3140#endif
3141 return MHD_NO; 3141 return MHD_NO;
3142 } 3142 }
3143 if ( (-1 != daemon->wpipe[0]) && 3143 if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) &&
3144 (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) ) 3144 (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) )
3145 { 3145 {
3146 event.events = EPOLLIN | EPOLLET; 3146 event.events = EPOLLIN | EPOLLET;
@@ -3250,8 +3250,8 @@ MHD_start_daemon_va (unsigned int flags,
3250 daemon->pool_increment = MHD_BUF_INC_SIZE; 3250 daemon->pool_increment = MHD_BUF_INC_SIZE;
3251 daemon->unescape_callback = &MHD_http_unescape; 3251 daemon->unescape_callback = &MHD_http_unescape;
3252 daemon->connection_timeout = 0; /* no timeout */ 3252 daemon->connection_timeout = 0; /* no timeout */
3253 daemon->wpipe[0] = -1; 3253 daemon->wpipe[0] = MHD_INVALID_PIPE_;
3254 daemon->wpipe[1] = -1; 3254 daemon->wpipe[1] = MHD_INVALID_PIPE_;
3255#if HAVE_MESSAGES 3255#if HAVE_MESSAGES
3256 daemon->custom_error_log = (MHD_LogCallback) &vfprintf; 3256 daemon->custom_error_log = (MHD_LogCallback) &vfprintf;
3257 daemon->custom_error_log_cls = stderr; 3257 daemon->custom_error_log_cls = stderr;
@@ -3263,13 +3263,7 @@ MHD_start_daemon_va (unsigned int flags,
3263#endif 3263#endif
3264 if (0 == (flags & (MHD_USE_SELECT_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION))) 3264 if (0 == (flags & (MHD_USE_SELECT_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION)))
3265 use_pipe = 0; /* useless if we are using 'external' select */ 3265 use_pipe = 0; /* useless if we are using 'external' select */
3266 if ( (use_pipe) && 3266 if ( (use_pipe) && (0 != MHD_pipe_ (daemon->wpipe)) )
3267#ifdef WINDOWS
3268 (0 != SOCKETPAIR (AF_INET, SOCK_STREAM, IPPROTO_TCP, daemon->wpipe))
3269#else
3270 (0 != PIPE (daemon->wpipe))
3271#endif
3272 )
3273 { 3267 {
3274#if HAVE_MESSAGES 3268#if HAVE_MESSAGES
3275 MHD_DLOG (daemon, 3269 MHD_DLOG (daemon,
@@ -3288,9 +3282,9 @@ MHD_start_daemon_va (unsigned int flags,
3288 MHD_DLOG (daemon, 3282 MHD_DLOG (daemon,
3289 "file descriptor for control pipe exceeds maximum value\n"); 3283 "file descriptor for control pipe exceeds maximum value\n");
3290#endif 3284#endif
3291 if (0 != CLOSE (daemon->wpipe[0])) 3285 if (0 != MHD_pipe_close_ (daemon->wpipe[0]))
3292 MHD_PANIC ("close failed\n"); 3286 MHD_PANIC ("close failed\n");
3293 if (0 != CLOSE (daemon->wpipe[1])) 3287 if (0 != MHD_pipe_close_ (daemon->wpipe[1]))
3294 MHD_PANIC ("close failed\n"); 3288 MHD_PANIC ("close failed\n");
3295 free (daemon); 3289 free (daemon);
3296 return NULL; 3290 return NULL;
@@ -3705,17 +3699,12 @@ MHD_start_daemon_va (unsigned int flags,
3705 d->worker_pool = NULL; 3699 d->worker_pool = NULL;
3706 3700
3707 if ( (MHD_USE_SUSPEND_RESUME == (flags & MHD_USE_SUSPEND_RESUME)) && 3701 if ( (MHD_USE_SUSPEND_RESUME == (flags & MHD_USE_SUSPEND_RESUME)) &&
3708#ifdef WINDOWS 3702 (0 != MHD_pipe_ (d->wpipe)) )
3709 (0 != SOCKETPAIR (AF_INET, SOCK_STREAM, IPPROTO_TCP, d->wpipe))
3710#else
3711 (0 != PIPE (d->wpipe))
3712#endif
3713 )
3714 { 3703 {
3715#if HAVE_MESSAGES 3704#if HAVE_MESSAGES
3716 MHD_DLOG (daemon, 3705 MHD_DLOG (daemon,
3717 "Failed to create worker control pipe: %s\n", 3706 "Failed to create worker control pipe: %s\n",
3718 MHD_strerror_ (errno)); 3707 MHD_pipe_last_strerror_() );
3719#endif 3708#endif
3720 goto thread_failed; 3709 goto thread_failed;
3721 } 3710 }
@@ -3728,9 +3717,9 @@ MHD_start_daemon_va (unsigned int flags,
3728 MHD_DLOG (daemon, 3717 MHD_DLOG (daemon,
3729 "file descriptor for worker control pipe exceeds maximum value\n"); 3718 "file descriptor for worker control pipe exceeds maximum value\n");
3730#endif 3719#endif
3731 if (0 != CLOSE (d->wpipe[0])) 3720 if (0 != MHD_pipe_close_ (d->wpipe[0]))
3732 MHD_PANIC ("close failed\n"); 3721 MHD_PANIC ("close failed\n");
3733 if (0 != CLOSE (d->wpipe[1])) 3722 if (0 != MHD_pipe_close_ (d->wpipe[1]))
3734 MHD_PANIC ("close failed\n"); 3723 MHD_PANIC ("close failed\n");
3735 goto thread_failed; 3724 goto thread_failed;
3736 } 3725 }
@@ -3906,7 +3895,7 @@ epoll_shutdown (struct MHD_Daemon *daemon)
3906{ 3895{
3907 struct epoll_event event; 3896 struct epoll_event event;
3908 3897
3909 if (-1 == daemon->wpipe[1]) 3898 if (MHD_INVALID_PIPE_ == daemon->wpipe[1])
3910 { 3899 {
3911 /* wpipe was required in this mode, how could this happen? */ 3900 /* wpipe was required in this mode, how could this happen? */
3912 MHD_PANIC ("Internal error\n"); 3901 MHD_PANIC ("Internal error\n");
@@ -3957,9 +3946,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3957#endif 3946#endif
3958 } 3947 }
3959 } 3948 }
3960 if (-1 != daemon->wpipe[1]) 3949 if (MHD_INVALID_PIPE_ != daemon->wpipe[1])
3961 { 3950 {
3962 if (1 != WRITE (daemon->wpipe[1], "e", 1)) 3951 if (1 != MHD_pipe_write_ (daemon->wpipe[1], "e", 1))
3963 MHD_PANIC ("failed to signal shutdown via pipe"); 3952 MHD_PANIC ("failed to signal shutdown via pipe");
3964 } 3953 }
3965#ifdef HAVE_LISTEN_SHUTDOWN 3954#ifdef HAVE_LISTEN_SHUTDOWN
@@ -3990,9 +3979,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3990 /* MHD_USE_NO_LISTEN_SOCKET disables thread pools, hence we need to check */ 3979 /* MHD_USE_NO_LISTEN_SOCKET disables thread pools, hence we need to check */
3991 for (i = 0; i < daemon->worker_pool_size; ++i) 3980 for (i = 0; i < daemon->worker_pool_size; ++i)
3992 { 3981 {
3993 if (-1 != daemon->worker_pool[i].wpipe[1]) 3982 if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1])
3994 { 3983 {
3995 if (1 != WRITE (daemon->worker_pool[i].wpipe[1], "e", 1)) 3984 if (1 != MHD_pipe_write_ (daemon->worker_pool[i].wpipe[1], "e", 1))
3996 MHD_PANIC ("failed to signal shutdown via pipe"); 3985 MHD_PANIC ("failed to signal shutdown via pipe");
3997 } 3986 }
3998 if (0 != (rc = pthread_join (daemon->worker_pool[i].pid, &unused))) 3987 if (0 != (rc = pthread_join (daemon->worker_pool[i].pid, &unused)))
@@ -4006,11 +3995,11 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
4006#endif 3995#endif
4007 if ( (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) ) 3996 if ( (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) )
4008 { 3997 {
4009 if (-1 != daemon->worker_pool[i].wpipe[1]) 3998 if (MHD_INVALID_PIPE_ != daemon->worker_pool[i].wpipe[1])
4010 { 3999 {
4011 if (0 != CLOSE (daemon->worker_pool[i].wpipe[0])) 4000 if (0 != MHD_pipe_close_ (daemon->worker_pool[i].wpipe[0]))
4012 MHD_PANIC ("close failed\n"); 4001 MHD_PANIC ("close failed\n");
4013 if (0 != CLOSE (daemon->worker_pool[i].wpipe[1])) 4002 if (0 != MHD_pipe_close_ (daemon->worker_pool[i].wpipe[1]))
4014 MHD_PANIC ("close failed\n"); 4003 MHD_PANIC ("close failed\n");
4015 } 4004 }
4016 } 4005 }
@@ -4058,11 +4047,11 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
4058 pthread_mutex_destroy (&daemon->per_ip_connection_mutex); 4047 pthread_mutex_destroy (&daemon->per_ip_connection_mutex);
4059 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 4048 pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
4060 4049
4061 if (-1 != daemon->wpipe[1]) 4050 if (MHD_INVALID_PIPE_ != daemon->wpipe[1])
4062 { 4051 {
4063 if (0 != CLOSE (daemon->wpipe[0])) 4052 if (0 != MHD_pipe_close_ (daemon->wpipe[0]))
4064 MHD_PANIC ("close failed\n"); 4053 MHD_PANIC ("close failed\n");
4065 if (0 != CLOSE (daemon->wpipe[1])) 4054 if (0 != MHD_pipe_close_ (daemon->wpipe[1]))
4066 MHD_PANIC ("close failed\n"); 4055 MHD_PANIC ("close failed\n");
4067 } 4056 }
4068 free (daemon); 4057 free (daemon);