libwebsockets
Lightweight C library for HTML5 websockets
lws-timeout-timer.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010-2018 Andy Green <andy@warmcat.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation:
9  * version 2.1 of the License.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  *
21  * included from libwebsockets.h
22  */
23 
29 
30 /*
31  * NOTE: These public enums are part of the abi. If you want to add one,
32  * add it at where specified so existing users are unaffected.
33  */
34 enum pending_timeout {
35  NO_PENDING_TIMEOUT = 0,
36  PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1,
37  PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2,
38  PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3,
39  PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4,
40  PENDING_TIMEOUT_AWAITING_PING = 5,
41  PENDING_TIMEOUT_CLOSE_ACK = 6,
42  PENDING_TIMEOUT_UNUSED1 = 7,
43  PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8,
44  PENDING_TIMEOUT_SSL_ACCEPT = 9,
45  PENDING_TIMEOUT_HTTP_CONTENT = 10,
46  PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11,
47  PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12,
48  PENDING_TIMEOUT_SHUTDOWN_FLUSH = 13,
49  PENDING_TIMEOUT_CGI = 14,
50  PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE = 15,
51  PENDING_TIMEOUT_WS_PONG_CHECK_SEND_PING = 16,
52  PENDING_TIMEOUT_WS_PONG_CHECK_GET_PONG = 17,
53  PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD = 18,
54  PENDING_TIMEOUT_AWAITING_SOCKS_GREETING_REPLY = 19,
55  PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY = 20,
56  PENDING_TIMEOUT_AWAITING_SOCKS_AUTH_REPLY = 21,
57  PENDING_TIMEOUT_KILLED_BY_SSL_INFO = 22,
58  PENDING_TIMEOUT_KILLED_BY_PARENT = 23,
59  PENDING_TIMEOUT_CLOSE_SEND = 24,
60  PENDING_TIMEOUT_HOLDING_AH = 25,
61  PENDING_TIMEOUT_UDP_IDLE = 26,
62  PENDING_TIMEOUT_CLIENT_CONN_IDLE = 27,
63  PENDING_TIMEOUT_LAGGING = 28,
64  PENDING_TIMEOUT_THREADPOOL = 29,
65  PENDING_TIMEOUT_THREADPOOL_TASK = 30,
66  PENDING_TIMEOUT_KILLED_BY_PROXY_CLIENT_CLOSE = 31,
67  PENDING_TIMEOUT_USER_OK = 32,
68 
69  /****** add new things just above ---^ ******/
70 
71  PENDING_TIMEOUT_USER_REASON_BASE = 1000
72 };
73 
74 #define lws_time_in_microseconds lws_now_usecs
75 
76 #define LWS_TO_KILL_ASYNC -1
83 #define LWS_TO_KILL_SYNC -2
99 LWS_VISIBLE LWS_EXTERN void
100 lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
101 
112 void
113 lws_set_timeout_us(struct lws *wsi, enum pending_timeout reason, lws_usec_t us);
114 
115 #define LWS_SET_TIMER_USEC_CANCEL ((lws_usec_t)-1ll)
116 #define LWS_USEC_PER_SEC ((lws_usec_t)1000000)
117 
145 LWS_VISIBLE LWS_EXTERN void
146 lws_set_timer_usecs(struct lws *wsi, lws_usec_t usecs);
147 
148 /*
149  * lws_timed_callback_vh_protocol() - calls back a protocol on a vhost after
150  * the specified delay in seconds
151  *
152  * \param vh: the vhost to call back
153  * \param protocol: the protocol to call back
154  * \param reason: callback reason
155  * \param secs: how many seconds in the future to do the callback.
156  *
157  * Callback the specified protocol with a fake wsi pointing to the specified
158  * vhost and protocol, with the specified reason, at the specified time in the
159  * future.
160  *
161  * Returns 0 if OK or 1 on OOM.
162  *
163  * In the multithreaded service case, the callback will occur in the same
164  * service thread context as the call to this api that requested it. If it is
165  * called from a non-service thread, tsi 0 will handle it.
166  */
167 LWS_VISIBLE LWS_EXTERN int
168 lws_timed_callback_vh_protocol(struct lws_vhost *vh,
169  const struct lws_protocols *prot,
170  int reason, int secs);
171 
172 /*
173  * lws_timed_callback_vh_protocol_us() - calls back a protocol on a vhost after
174  * the specified delay in us
175  *
176  * \param vh: the vhost to call back
177  * \param protocol: the protocol to call back
178  * \param reason: callback reason
179  * \param us: how many us in the future to do the callback.
180  *
181  * Callback the specified protocol with a fake wsi pointing to the specified
182  * vhost and protocol, with the specified reason, at the specified time in the
183  * future.
184  *
185  * Returns 0 if OK or 1 on OOM.
186  *
187  * In the multithreaded service case, the callback will occur in the same
188  * service thread context as the call to this api that requested it. If it is
189  * called from a non-service thread, tsi 0 will handle it.
190  */
191 LWS_VISIBLE LWS_EXTERN int
192 lws_timed_callback_vh_protocol_us(struct lws_vhost *vh,
193  const struct lws_protocols *prot, int reason,
194  lws_usec_t us);
195 
196 
197 typedef void (*sul_cb_t)(lws_sorted_usec_list_t *sul);
198 
200  struct lws_dll2 list; /* simplify the code by keeping this at start */
201  sul_cb_t cb;
202  lws_usec_t us;
203 };
204 
205 
206 /*
207  * lws_sul_schedule() - schedule a callback
208  *
209  * \param context: the lws_context
210  * \param tsi: the thread service index (usually 0)
211  * \param sul: pointer to the sul element
212  * \param cb: the scheduled callback
213  * \param us: the delay before the callback arrives, or
214  * LWS_SET_TIMER_USEC_CANCEL to cancel it.
215  *
216  * Generic callback-at-a-later time function. The callback happens on the
217  * event loop thread context.
218  *
219  * Although the api has us resultion, the actual resolution depends on the
220  * platform and is commonly 1ms.
221  *
222  * This doesn't allocate and doesn't fail.
223  *
224  * You can call it again with another us value to change the delay.
225  */
226 LWS_VISIBLE LWS_EXTERN void
227 lws_sul_schedule(struct lws_context *context, int tsi,
228  lws_sorted_usec_list_t *sul, sul_cb_t cb, lws_usec_t us);
229 
Definition: lws-misc.h:253
Definition: lws-protocols-plugins.h:43
Definition: lws-timeout-timer.h:199