aboutsummaryrefslogtreecommitdiff
path: root/src/lib/daemon_destroy.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-17 16:56:41 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-17 16:56:41 +0200
commit972103dc288e2a2396e060018e7c3733f29a940d (patch)
treeaeb0b3a182d5168f12752928d3204342c9581e91 /src/lib/daemon_destroy.c
parentcbbfd0591fc639ddd21a5850f54f403fb7394174 (diff)
downloadlibmicrohttpd-972103dc288e2a2396e060018e7c3733f29a940d.tar.gz
libmicrohttpd-972103dc288e2a2396e060018e7c3733f29a940d.zip
applying uncrustify to ensure uniform indentation
Diffstat (limited to 'src/lib/daemon_destroy.c')
-rw-r--r--src/lib/daemon_destroy.c158
1 files changed, 80 insertions, 78 deletions
diff --git a/src/lib/daemon_destroy.c b/src/lib/daemon_destroy.c
index b4f34d16..a76c2d6b 100644
--- a/src/lib/daemon_destroy.c
+++ b/src/lib/daemon_destroy.c
@@ -46,35 +46,36 @@ stop_workers (struct MHD_Daemon *daemon)
46 fd = daemon->listen_socket; 46 fd = daemon->listen_socket;
47 /* Let workers shutdown in parallel. */ 47 /* Let workers shutdown in parallel. */
48 for (i = 0; i < daemon->worker_pool_size; i++) 48 for (i = 0; i < daemon->worker_pool_size; i++)
49 {
50 daemon->worker_pool[i].shutdown = true;
51 if (MHD_ITC_IS_VALID_ (daemon->worker_pool[i].itc))
49 { 52 {
50 daemon->worker_pool[i].shutdown = true; 53 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc,
51 if (MHD_ITC_IS_VALID_(daemon->worker_pool[i].itc)) 54 "e"))
52 { 55 MHD_PANIC (_ (
53 if (! MHD_itc_activate_ (daemon->worker_pool[i].itc, 56 "Failed to signal shutdown via inter-thread communication channel."));
54 "e"))
55 MHD_PANIC (_("Failed to signal shutdown via inter-thread communication channel."));
56 }
57 else
58 {
59 /* Better hope shutdown() works... */
60 mhd_assert (MHD_INVALID_SOCKET != fd);
61 }
62 } 57 }
63#ifdef HAVE_LISTEN_SHUTDOWN 58 else
64 if (MHD_INVALID_SOCKET != fd)
65 { 59 {
66 (void) shutdown (fd, 60 /* Better hope shutdown() works... */
67 SHUT_RDWR); 61 mhd_assert (MHD_INVALID_SOCKET != fd);
68 } 62 }
63 }
64#ifdef HAVE_LISTEN_SHUTDOWN
65 if (MHD_INVALID_SOCKET != fd)
66 {
67 (void) shutdown (fd,
68 SHUT_RDWR);
69 }
69#endif /* HAVE_LISTEN_SHUTDOWN */ 70#endif /* HAVE_LISTEN_SHUTDOWN */
70 for (i = 0; i < daemon->worker_pool_size; ++i) 71 for (i = 0; i < daemon->worker_pool_size; ++i)
71 { 72 {
72 MHD_daemon_destroy (&daemon->worker_pool[i]); 73 MHD_daemon_destroy (&daemon->worker_pool[i]);
73 } 74 }
74 free (daemon->worker_pool); 75 free (daemon->worker_pool);
75 daemon->worker_pool = NULL; 76 daemon->worker_pool = NULL;
76 /* FIXME: does this still hold? */ 77 /* FIXME: does this still hold? */
77 mhd_assert (MHD_ITC_IS_INVALID_(daemon->itc)); 78 mhd_assert (MHD_ITC_IS_INVALID_ (daemon->itc));
78#ifdef EPOLL_SUPPORT 79#ifdef EPOLL_SUPPORT
79 mhd_assert (-1 == daemon->epoll_fd); 80 mhd_assert (-1 == daemon->epoll_fd);
80#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 81#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
@@ -104,65 +105,66 @@ MHD_daemon_destroy (struct MHD_Daemon *daemon)
104 /* FIXME: convert from here to microhttpd2-style API! */ 105 /* FIXME: convert from here to microhttpd2-style API! */
105 106
106 if (NULL != daemon->worker_pool) 107 if (NULL != daemon->worker_pool)
107 { /* Master daemon with worker pool. */ 108 { /* Master daemon with worker pool. */
108 stop_workers (daemon); 109 stop_workers (daemon);
109 } 110 }
110 else 111 else
112 {
113 mhd_assert (0 == daemon->worker_pool_size);
114 /* Worker daemon or single-thread daemon. */
115 if (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode)
111 { 116 {
112 mhd_assert (0 == daemon->worker_pool_size); 117 /* Worker daemon or single daemon with internal thread(s). */
113 /* Worker daemon or single-thread daemon. */ 118 /* Separate thread(s) is used for polling sockets. */
114 if (MHD_TM_EXTERNAL_EVENT_LOOP != daemon->threading_mode) 119 if (MHD_ITC_IS_VALID_ (daemon->itc))
115 { 120 {
116 /* Worker daemon or single daemon with internal thread(s). */ 121 if (! MHD_itc_activate_ (daemon->itc,
117 /* Separate thread(s) is used for polling sockets. */ 122 "e"))
118 if (MHD_ITC_IS_VALID_(daemon->itc)) 123 MHD_PANIC (_ (
119 { 124 "Failed to signal shutdown via inter-thread communication channel"));
120 if (! MHD_itc_activate_ (daemon->itc, 125 }
121 "e"))
122 MHD_PANIC (_("Failed to signal shutdown via inter-thread communication channel"));
123 }
124 else
125 {
126#ifdef HAVE_LISTEN_SHUTDOWN
127 if (MHD_INVALID_SOCKET != fd)
128 {
129 if (NULL == daemon->master)
130 (void) shutdown (fd,
131 SHUT_RDWR);
132 }
133 else
134#endif /* HAVE_LISTEN_SHUTDOWN */
135 mhd_assert (false); /* Should never happen */
136 }
137
138 if (! MHD_join_thread_ (daemon->pid.handle))
139 {
140 MHD_PANIC (_("Failed to join a thread\n"));
141 }
142 /* close_all_connections() was called in daemon thread. */
143 }
144 else 126 else
127 {
128#ifdef HAVE_LISTEN_SHUTDOWN
129 if (MHD_INVALID_SOCKET != fd)
145 { 130 {
146 /* No internal threads are used for polling sockets 131 if (NULL == daemon->master)
147 (external event loop) */ 132 (void) shutdown (fd,
148 MHD_daemon_close_all_connections_ (daemon); 133 SHUT_RDWR);
149 } 134 }
150 if (MHD_ITC_IS_VALID_ (daemon->itc)) 135 else
151 MHD_itc_destroy_chk_ (daemon->itc); 136#endif /* HAVE_LISTEN_SHUTDOWN */
137 mhd_assert (false); /* Should never happen */
138 }
139
140 if (! MHD_join_thread_ (daemon->pid.handle))
141 {
142 MHD_PANIC (_ ("Failed to join a thread\n"));
143 }
144 /* close_all_connections() was called in daemon thread. */
145 }
146 else
147 {
148 /* No internal threads are used for polling sockets
149 (external event loop) */
150 MHD_daemon_close_all_connections_ (daemon);
151 }
152 if (MHD_ITC_IS_VALID_ (daemon->itc))
153 MHD_itc_destroy_chk_ (daemon->itc);
152 154
153#ifdef EPOLL_SUPPORT 155#ifdef EPOLL_SUPPORT
154 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && 156 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
155 (-1 != daemon->epoll_fd) ) 157 (-1 != daemon->epoll_fd) )
156 MHD_socket_close_chk_ (daemon->epoll_fd); 158 MHD_socket_close_chk_ (daemon->epoll_fd);
157#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 159#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
158 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) && 160 if ( (MHD_ELS_EPOLL == daemon->event_loop_syscall) &&
159 (-1 != daemon->epoll_upgrade_fd) ) 161 (-1 != daemon->epoll_upgrade_fd) )
160 MHD_socket_close_chk_ (daemon->epoll_upgrade_fd); 162 MHD_socket_close_chk_ (daemon->epoll_upgrade_fd);
161#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 163#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
162#endif /* EPOLL_SUPPORT */ 164#endif /* EPOLL_SUPPORT */
163 165
164 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex); 166 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
165 } 167 }
166 168
167 if (NULL != daemon->master) 169 if (NULL != daemon->master)
168 return; 170 return;
@@ -175,18 +177,18 @@ MHD_daemon_destroy (struct MHD_Daemon *daemon)
175 /* TLS clean up */ 177 /* TLS clean up */
176#ifdef HTTPS_SUPPORT 178#ifdef HTTPS_SUPPORT
177 if (NULL != daemon->tls_api) 179 if (NULL != daemon->tls_api)
178 { 180 {
179#if FIXME_TLS_API 181#if FIXME_TLS_API
180 if (daemon->have_dhparams) 182 if (daemon->have_dhparams)
181 { 183 {
182 gnutls_dh_params_deinit (daemon->https_mem_dhparams); 184 gnutls_dh_params_deinit (daemon->https_mem_dhparams);
183 daemon->have_dhparams = false; 185 daemon->have_dhparams = false;
184 }
185 gnutls_priority_deinit (daemon->priority_cache);
186 if (daemon->x509_cred)
187 gnutls_certificate_free_credentials (daemon->x509_cred);
188#endif
189 } 186 }
187 gnutls_priority_deinit (daemon->priority_cache);
188 if (daemon->x509_cred)
189 gnutls_certificate_free_credentials (daemon->x509_cred);
190#endif
191 }
190#endif /* HTTPS_SUPPORT */ 192#endif /* HTTPS_SUPPORT */
191 193
192#ifdef DAUTH_SUPPORT 194#ifdef DAUTH_SUPPORT