diff options
Diffstat (limited to 'src/lib/connection_update_last_activity.c')
-rw-r--r-- | src/lib/connection_update_last_activity.c | 65 |
1 files changed, 65 insertions, 0 deletions
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 | |||