diff options
Diffstat (limited to 'src/lib/connection_close.c')
-rw-r--r-- | src/lib/connection_close.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/lib/connection_close.c b/src/lib/connection_close.c new file mode 100644 index 00000000..39045e9f --- /dev/null +++ b/src/lib/connection_close.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | /** | ||
20 | * @file lib/connection_close.c | ||
21 | * @brief functions to close a connection | ||
22 | * @author Christian Grothoff | ||
23 | */ | ||
24 | #include "internal.h" | ||
25 | #include "connection_close.h" | ||
26 | |||
27 | |||
28 | /** | ||
29 | * Mark connection as "closed". | ||
30 | * | ||
31 | * @remark To be called from any thread. | ||
32 | * | ||
33 | * @param connection connection to close | ||
34 | */ | ||
35 | void | ||
36 | MHD_connection_mark_closed_ (struct MHD_Connection *connection) | ||
37 | { | ||
38 | const struct MHD_Daemon *daemon = connection->daemon; | ||
39 | |||
40 | connection->request.state = MHD_REQUEST_CLOSED; | ||
41 | connection->request.event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; | ||
42 | if (! daemon->enable_turbo) | ||
43 | { | ||
44 | #ifdef HTTPS_SUPPORT | ||
45 | struct MHD_TLS_Plugin *tls; | ||
46 | |||
47 | /* For TLS connection use shutdown of TLS layer | ||
48 | * and do not shutdown TCP socket. This give more | ||
49 | * chances to send TLS closure data to remote side. | ||
50 | * Closure of TLS layer will be interpreted by | ||
51 | * remote side as end of transmission. */ | ||
52 | if (NULL != (tls = daemon->tls_api)) | ||
53 | { | ||
54 | if (MHD_YES != | ||
55 | tls->shutdown_connection (tls->cls, | ||
56 | connection->tls_cs)) | ||
57 | { | ||
58 | (void) shutdown (connection->socket_fd, | ||
59 | SHUT_WR); | ||
60 | /* FIXME: log errors */ | ||
61 | } | ||
62 | } | ||
63 | else /* Combined with next 'shutdown()'. */ | ||
64 | #endif /* HTTPS_SUPPORT */ | ||
65 | { | ||
66 | (void) shutdown (connection->socket_fd, | ||
67 | SHUT_WR); /* FIXME: log errors */ | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Close the given connection and give the specified termination code | ||
75 | * to the user. | ||
76 | * | ||
77 | * @remark To be called only from thread that process | ||
78 | * connection's recv(), send() and response. | ||
79 | * | ||
80 | * @param connection connection to close | ||
81 | * @param cnc termination reason to give | ||
82 | */ | ||
83 | void | ||
84 | MHD_connection_close_ (struct MHD_Connection *connection, | ||
85 | enum MHD_ConnectionNotificationCode cnc) | ||
86 | { | ||
87 | struct MHD_Daemon *daemon = connection->daemon; | ||
88 | struct MHD_Response *resp = connection->request.response; | ||
89 | |||
90 | MHD_connection_mark_closed_ (connection); | ||
91 | if (NULL != resp) | ||
92 | { | ||
93 | connection->request.response = NULL; | ||
94 | MHD_response_queue_for_destroy (resp); | ||
95 | } | ||
96 | if ( (NULL != daemon->notify_connection_cb) && | ||
97 | (connection->client_aware) ) | ||
98 | daemon->notify_connection_cb (daemon->notify_connection_cb_cls, | ||
99 | connection, | ||
100 | cnc); | ||
101 | connection->client_aware = false; | ||
102 | } | ||
103 | |||
104 | /* end of connection_close.c */ | ||