GNU libmicrohttpd  0.9.72
connection_options.c
Go to the documentation of this file.
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 
25 #include "internal.h"
26 
27 
36 void
38  unsigned int timeout_s)
39 {
40  struct MHD_Daemon *daemon = connection->daemon;
41 
43  if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode)
44  {
45  /* Simple case, no need to lock to update DLLs */
46  connection->connection_timeout = (time_t) timeout_s;
47  return;
48  }
49 
51  if (! connection->suspended)
52  {
53  if (connection->connection_timeout ==
56  daemon->normal_timeout_tail,
57  connection);
58  else
60  daemon->manual_timeout_tail,
61  connection);
62  }
63  connection->connection_timeout = (time_t) timeout_s;
64  if (! connection->suspended)
65  {
66  if (connection->connection_timeout ==
69  daemon->normal_timeout_tail,
70  connection);
71  else
73  daemon->manual_timeout_tail,
74  connection);
75  }
77 }
78 
79 
87 void
89 {
90  struct MHD_Daemon *daemon = connection->daemon;
91 
92  if (0 == connection->connection_timeout)
93  return; /* Skip update of activity for connections
94  without timeout timer. */
95  if (connection->suspended)
96  return; /* no activity on suspended connections */
97 
99  if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_mode)
100  return; /* each connection has personal timeout */
101 
102  if (connection->connection_timeout !=
104  return; /* custom timeout, no need to move it in "normal" DLL */
105 
107  /* move connection to head of timeout list (by remove + add operation) */
109  daemon->normal_timeout_tail,
110  connection);
112  daemon->normal_timeout_tail,
113  connection);
115 }
116 
117 
118 /* end of connection_options.c */
void MHD_update_last_activity_(struct MHD_Connection *connection)
void MHD_connection_set_timeout(struct MHD_Connection *connection, unsigned int timeout_s)
#define XDLL_insert(head, tail, element)
Definition: internal.h:1786
#define XDLL_remove(head, tail, element)
Definition: internal.h:1806
#define MHD_mutex_unlock_chk_(pmutex)
Definition: mhd_locks.h:180
#define MHD_mutex_lock_chk_(pmutex)
Definition: mhd_locks.h:154
time_t MHD_monotonic_sec_counter(void)
internal shared structures
bool suspended
Definition: internal.h:764
time_t connection_timeout
Definition: internal.h:745
time_t last_activity
Definition: internal.h:739
struct MHD_Daemon * daemon
Definition: internal.h:675
MHD_mutex_ cleanup_connection_mutex
Definition: internal.h:1265
struct MHD_Connection * manual_timeout_tail
Definition: internal.h:1150
time_t connection_default_timeout
Definition: internal.h:1371
struct MHD_Connection * manual_timeout_head
Definition: internal.h:1143
struct MHD_Connection * normal_timeout_head
Definition: internal.h:1128
struct MHD_Connection * normal_timeout_tail
Definition: internal.h:1135
enum MHD_ThreadingMode threading_mode
Definition: internal.h:1417