aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r--src/daemon/daemon.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 2dd7551f..3b8b1111 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -228,6 +228,7 @@ MHD_handle_connection (void *data)
228 MHD_DLOG (con->daemon, 228 MHD_DLOG (con->daemon,
229 "Processing thread terminating, closing connection\n"); 229 "Processing thread terminating, closing connection\n");
230#endif 230#endif
231 SHUTDOWN (con->socket_fd, SHUT_RDWR);
231 CLOSE (con->socket_fd); 232 CLOSE (con->socket_fd);
232 con->socket_fd = -1; 233 con->socket_fd = -1;
233 } 234 }
@@ -258,8 +259,10 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
258 if ((s < 0) || (addrlen <= 0)) 259 if ((s < 0) || (addrlen <= 0))
259 { 260 {
260 MHD_DLOG (daemon, "Error accepting connection: %s\n", STRERROR (errno)); 261 MHD_DLOG (daemon, "Error accepting connection: %s\n", STRERROR (errno));
261 if (s != -1) 262 if (s != -1) {
263 SHUTDOWN (s, SHUT_RDWR);
262 CLOSE (s); /* just in case */ 264 CLOSE (s); /* just in case */
265 }
263 return MHD_NO; 266 return MHD_NO;
264 } 267 }
265 if (daemon->max_connections == 0) 268 if (daemon->max_connections == 0)
@@ -267,6 +270,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
267 /* above connection limit - reject */ 270 /* above connection limit - reject */
268 MHD_DLOG (daemon, 271 MHD_DLOG (daemon,
269 "Server reached connection limit (closing inbound connection)\n"); 272 "Server reached connection limit (closing inbound connection)\n");
273 SHUTDOWN (s, SHUT_RDWR);
270 CLOSE (s); 274 CLOSE (s);
271 return MHD_NO; 275 return MHD_NO;
272 } 276 }
@@ -277,6 +281,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
277 MHD_DLOG (daemon, 281 MHD_DLOG (daemon,
278 "Connection rejected, closing connection\n"); 282 "Connection rejected, closing connection\n");
279#endif 283#endif
284 SHUTDOWN (s, SHUT_RDWR);
280 CLOSE (s); 285 CLOSE (s);
281 return MHD_YES; 286 return MHD_YES;
282 } 287 }
@@ -284,6 +289,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
284 if (connection == NULL) 289 if (connection == NULL)
285 { 290 {
286 MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); 291 MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno));
292 SHUTDOWN (s, SHUT_RDWR);
287 CLOSE (s); 293 CLOSE (s);
288 return MHD_NO; 294 return MHD_NO;
289 } 295 }
@@ -293,6 +299,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
293 if (connection->addr == NULL) 299 if (connection->addr == NULL)
294 { 300 {
295 MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno)); 301 MHD_DLOG (daemon, "Error allocating memory: %s\n", STRERROR (errno));
302 SHUTDOWN (s, SHUT_RDWR);
296 CLOSE (s); 303 CLOSE (s);
297 free (connection); 304 free (connection);
298 return MHD_NO; 305 return MHD_NO;
@@ -306,6 +313,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
306 NULL, &MHD_handle_connection, connection))) 313 NULL, &MHD_handle_connection, connection)))
307 { 314 {
308 MHD_DLOG (daemon, "Failed to create a thread: %s\n", STRERROR (errno)); 315 MHD_DLOG (daemon, "Failed to create a thread: %s\n", STRERROR (errno));
316 SHUTDOWN (s, SHUT_RDWR);
309 CLOSE (s); 317 CLOSE (s);
310 free (connection->addr); 318 free (connection->addr);
311 free (connection); 319 free (connection);
@@ -352,6 +360,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
352 MHD_DLOG (daemon, 360 MHD_DLOG (daemon,
353 "Connection timed out, closing connection\n"); 361 "Connection timed out, closing connection\n");
354#endif 362#endif
363 SHUTDOWN (pos->socket_fd, SHUT_RDWR);
355 CLOSE (pos->socket_fd); 364 CLOSE (pos->socket_fd);
356 pos->socket_fd = -1; 365 pos->socket_fd = -1;
357 if (pos->daemon->notify_completed != NULL) 366 if (pos->daemon->notify_completed != NULL)
@@ -747,7 +756,8 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
747 daemon->connections, 756 daemon->connections,
748 &daemon->connections->client_context, 757 &daemon->connections->client_context,
749 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN); 758 MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN);
750 CLOSE (daemon->connections->socket_fd); 759 SHUTDOWN (daemon->connections->socket_fd, SHUT_RDWR);
760 CLOSE (daemon->connections->socket_fd);
751 daemon->connections->socket_fd = -1; 761 daemon->connections->socket_fd = -1;
752 } 762 }
753 MHD_cleanup_connections (daemon); 763 MHD_cleanup_connections (daemon);