diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-02-16 04:39:07 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-02-16 04:39:07 +0100 |
commit | 0ca235616cb8f2ebfa7cebb7fabef1ff678a6377 (patch) | |
tree | 4f9c83c13a75d61b84e0d8a4972f7cb40c0cc986 | |
parent | 9bf8e55fe1b8306e1319956dab78b462477a4b63 (diff) | |
download | libmicrohttpd-0ca235616cb8f2ebfa7cebb7fabef1ff678a6377.tar.gz libmicrohttpd-0ca235616cb8f2ebfa7cebb7fabef1ff678a6377.zip |
more work on new src/lib implementation: connection_update_last_activity and connection_close handling
-rw-r--r-- | src/gnutls/shutdown_connection.c | 5 | ||||
-rw-r--r-- | src/lib/connection_close.c | 104 | ||||
-rw-r--r-- | src/lib/connection_close.h | 55 | ||||
-rw-r--r-- | src/lib/connection_update_last_activity.c | 65 | ||||
-rw-r--r-- | src/lib/connection_update_last_activity.h | 40 |
5 files changed, 269 insertions, 0 deletions
diff --git a/src/gnutls/shutdown_connection.c b/src/gnutls/shutdown_connection.c new file mode 100644 index 00000000..be1e0bde --- /dev/null +++ b/src/gnutls/shutdown_connection.c | |||
@@ -0,0 +1,5 @@ | |||
1 | enum MHD_Bool | ||
2 | (*shutdown_connection) (void *cls, | ||
3 | struct MHD_TLS_ConnectionState *cs); | ||
4 | |||
5 | see: MHD_tls_connection_shutdown() | ||
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 */ | ||
diff --git a/src/lib/connection_close.h b/src/lib/connection_close.h new file mode 100644 index 00000000..db1778bb --- /dev/null +++ b/src/lib/connection_close.h | |||
@@ -0,0 +1,55 @@ | |||
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.h | ||
21 | * @brief functions to close connection | ||
22 | * @author Christian Grothoff | ||
23 | */ | ||
24 | |||
25 | #ifndef CONNECTION_CLOSE_H | ||
26 | #define CONNECTION_CLOSE_H | ||
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 | MHD_NONNULL (1); | ||
38 | |||
39 | |||
40 | /** | ||
41 | * Close the given connection and give the specified termination code | ||
42 | * to the user. | ||
43 | * | ||
44 | * @remark To be called only from thread that process | ||
45 | * connection's recv(), send() and response. | ||
46 | * | ||
47 | * @param connection connection to close | ||
48 | * @param cnc termination reason to give | ||
49 | */ | ||
50 | void | ||
51 | MHD_connection_close_ (struct MHD_Connection *connection, | ||
52 | enum MHD_ConnectionNotificationCode cnc) | ||
53 | MHD_NONNULL (1); | ||
54 | |||
55 | #endif | ||
diff --git a/src/lib/connection_update_last_activity.c b/src/lib/connection_update_last_activity.c new file mode 100644 index 00000000..e235d458 --- /dev/null +++ b/src/lib/connection_update_last_activity.c | |||
@@ -0,0 +1,65 @@ | |||
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_add.c | ||
21 | * @brief functions to add connection to our active set | ||
22 | * @author Christian Grothoff | ||
23 | */ | ||
24 | #include "internal.h" | ||
25 | #include "connection_update_last_activity.h" | ||
26 | |||
27 | |||
28 | /** | ||
29 | * Update the 'last_activity' field of the connection to the current time | ||
30 | * and move the connection to the head of the 'normal_timeout' list if | ||
31 | * the timeout for the connection uses the default value. | ||
32 | * | ||
33 | * @param connection the connection that saw some activity | ||
34 | */ | ||
35 | void | ||
36 | MHD_connection_update_last_activity_ (struct MHD_Connection *connection) | ||
37 | { | ||
38 | struct MHD_Daemon *daemon = connection->daemon; | ||
39 | |||
40 | if (0 == connection->connection_timeout) | ||
41 | return; /* Skip update of activity for connections | ||
42 | without timeout timer. */ | ||
43 | if (connection->suspended) | ||
44 | return; /* no activity on suspended connections */ | ||
45 | |||
46 | connection->last_activity = MHD_monotonic_sec_counter(); | ||
47 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | ||
48 | return; /* each connection has personal timeout */ | ||
49 | |||
50 | if (connection->connection_timeout != daemon->connection_timeout) | ||
51 | return; /* custom timeout, no need to move it in "normal" DLL */ | ||
52 | |||
53 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | ||
54 | /* move connection to head of timeout list (by remove + add operation) */ | ||
55 | XDLL_remove (daemon->normal_timeout_head, | ||
56 | daemon->normal_timeout_tail, | ||
57 | connection); | ||
58 | XDLL_insert (daemon->normal_timeout_head, | ||
59 | daemon->normal_timeout_tail, | ||
60 | connection); | ||
61 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | ||
62 | } | ||
63 | |||
64 | /* end of connection_update_last_activity.c */ | ||
65 | |||
diff --git a/src/lib/connection_update_last_activity.h b/src/lib/connection_update_last_activity.h new file mode 100644 index 00000000..8383b6be --- /dev/null +++ b/src/lib/connection_update_last_activity.h | |||
@@ -0,0 +1,40 @@ | |||
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_update_last_activity.h | ||
21 | * @brief function to update last activity of a connection | ||
22 | * @author Christian Grothoff | ||
23 | */ | ||
24 | |||
25 | #ifndef CONNECTION_UPDATE_LAST_ACTIVITY_H | ||
26 | #define CONNECTION_UPDATE_LAST_ACTIVITY_H | ||
27 | |||
28 | |||
29 | /** | ||
30 | * Update the 'last_activity' field of the connection to the current time | ||
31 | * and move the connection to the head of the 'normal_timeout' list if | ||
32 | * the timeout for the connection uses the default value. | ||
33 | * | ||
34 | * @param connection the connection that saw some activity | ||
35 | */ | ||
36 | void | ||
37 | MHD_connection_update_last_activity_ (struct MHD_Connection *connection) | ||
38 | MHD_NONNULL (1); | ||
39 | |||
40 | #endif | ||