libwebsockets
Lightweight C library for HTML5 websockets
lws-timeout-timer.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lws_sorted_usec_list
 

Macros

#define lws_time_in_microseconds   lws_now_usecs
 
#define LWS_TO_KILL_ASYNC   -1
 
#define LWS_TO_KILL_SYNC   -2
 
#define lws_wsi_close(w, to_kill)   lws_set_timeout(w, 1, to_kill)
 
#define LWS_SET_TIMER_USEC_CANCEL   ((lws_usec_t)-1ll)
 
#define LWS_USEC_PER_SEC   ((lws_usec_t)1000000)
 
#define LWS_COUNT_PT_SUL_OWNERS   2
 
#define LWSSULLI_MISS_IF_SUSPENDED   0
 
#define LWSSULLI_WAKE_IF_SUSPENDED   1
 
#define lws_sul_debug_zombies(_a, _b, _c, _d)
 

Typedefs

typedef void(* sul_cb_t) (struct lws_sorted_usec_list *sul)
 
typedef struct lws_sorted_usec_list lws_sorted_usec_list_t
 

Enumerations

enum  pending_timeout {
  NO_PENDING_TIMEOUT = 0 , PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1 , PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2 , PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3 ,
  PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4 , PENDING_TIMEOUT_AWAITING_PING = 5 , PENDING_TIMEOUT_CLOSE_ACK = 6 , PENDING_TIMEOUT_UNUSED1 = 7 ,
  PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8 , PENDING_TIMEOUT_SSL_ACCEPT = 9 , PENDING_TIMEOUT_HTTP_CONTENT = 10 , PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11 ,
  PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12 , PENDING_TIMEOUT_SHUTDOWN_FLUSH = 13 , PENDING_TIMEOUT_CGI = 14 , PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE = 15 ,
  PENDING_TIMEOUT_WS_PONG_CHECK_SEND_PING = 16 , PENDING_TIMEOUT_WS_PONG_CHECK_GET_PONG = 17 , PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD = 18 , PENDING_TIMEOUT_AWAITING_SOCKS_GREETING_REPLY = 19 ,
  PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY = 20 , PENDING_TIMEOUT_AWAITING_SOCKS_AUTH_REPLY = 21 , PENDING_TIMEOUT_KILLED_BY_SSL_INFO = 22 , PENDING_TIMEOUT_KILLED_BY_PARENT = 23 ,
  PENDING_TIMEOUT_CLOSE_SEND = 24 , PENDING_TIMEOUT_HOLDING_AH = 25 , PENDING_TIMEOUT_UDP_IDLE = 26 , PENDING_TIMEOUT_CLIENT_CONN_IDLE = 27 ,
  PENDING_TIMEOUT_LAGGING = 28 , PENDING_TIMEOUT_THREADPOOL = 29 , PENDING_TIMEOUT_THREADPOOL_TASK = 30 , PENDING_TIMEOUT_KILLED_BY_PROXY_CLIENT_CLOSE = 31 ,
  PENDING_TIMEOUT_USER_OK = 32 , PENDING_TIMEOUT_USER_REASON_BASE = 1000
}
 

Functions

LWS_VISIBLE LWS_EXTERN void lws_set_timeout (struct lws *wsi, enum pending_timeout reason, int secs)
 
void lws_set_timeout_us (struct lws *wsi, enum pending_timeout reason, lws_usec_t us)
 
LWS_VISIBLE LWS_EXTERN void lws_set_timer_usecs (struct lws *wsi, lws_usec_t usecs)
 
LWS_VISIBLE LWS_EXTERN void lws_sul2_schedule (struct lws_context *context, int tsi, int flags, lws_sorted_usec_list_t *sul)
 
LWS_VISIBLE LWS_EXTERN void lws_sul_cancel (lws_sorted_usec_list_t *sul)
 
LWS_VISIBLE LWS_EXTERN int lws_sul_earliest_wakeable_event (struct lws_context *ctx, lws_usec_t *pearliest)
 
LWS_VISIBLE LWS_EXTERN void lws_sul_schedule (struct lws_context *ctx, int tsi, lws_sorted_usec_list_t *sul, sul_cb_t _cb, lws_usec_t _us)
 
LWS_VISIBLE LWS_EXTERN void lws_sul_schedule_wakesuspend (struct lws_context *ctx, int tsi, lws_sorted_usec_list_t *sul, sul_cb_t _cb, lws_usec_t _us)
 
LWS_VISIBLE LWS_EXTERN void lws_validity_confirmed (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int __lws_sul_insert (lws_dll2_owner_t *own, lws_sorted_usec_list_t *sul)
 
LWS_VISIBLE LWS_EXTERN lws_usec_t __lws_sul_service_ripe (lws_dll2_owner_t *own, int own_len, lws_usec_t usnow)
 

Data Structure Documentation

◆ lws_sorted_usec_list

struct lws_sorted_usec_list

Definition at line 162 of file lws-timeout-timer.h.

+ Collaboration diagram for lws_sorted_usec_list:
Data Fields
struct lws_dll2 list
lws_usec_t us
sul_cb_t cb
uint32_t latency_us

Macro Definition Documentation

◆ lws_time_in_microseconds

#define lws_time_in_microseconds   lws_now_usecs

Definition at line 80 of file lws-timeout-timer.h.

◆ LWS_TO_KILL_ASYNC

#define LWS_TO_KILL_ASYNC   -1

If LWS_TO_KILL_ASYNC is given as the timeout sec in a lws_set_timeout() call, then the connection is marked to be killed at the next timeout check. This is how you should force-close the wsi being serviced if you are doing it outside the callback (where you should close by nonzero return).

Definition at line 88 of file lws-timeout-timer.h.

◆ LWS_TO_KILL_SYNC

#define LWS_TO_KILL_SYNC   -2

If LWS_TO_KILL_SYNC is given as the timeout sec in a lws_set_timeout() call, then the connection is closed before returning (which may delete the wsi). This should only be used where the wsi being closed is not the wsi currently being serviced.

Definition at line 94 of file lws-timeout-timer.h.

◆ lws_wsi_close

#define lws_wsi_close (   w,
  to_kill 
)    lws_set_timeout(w, 1, to_kill)

Definition at line 122 of file lws-timeout-timer.h.

◆ LWS_SET_TIMER_USEC_CANCEL

#define LWS_SET_TIMER_USEC_CANCEL   ((lws_usec_t)-1ll)

Definition at line 125 of file lws-timeout-timer.h.

◆ LWS_USEC_PER_SEC

#define LWS_USEC_PER_SEC   ((lws_usec_t)1000000)

Definition at line 126 of file lws-timeout-timer.h.

◆ LWS_COUNT_PT_SUL_OWNERS

#define LWS_COUNT_PT_SUL_OWNERS   2

Definition at line 173 of file lws-timeout-timer.h.

◆ LWSSULLI_MISS_IF_SUSPENDED

#define LWSSULLI_MISS_IF_SUSPENDED   0

Definition at line 175 of file lws-timeout-timer.h.

◆ LWSSULLI_WAKE_IF_SUSPENDED

#define LWSSULLI_WAKE_IF_SUSPENDED   1

Definition at line 176 of file lws-timeout-timer.h.

◆ lws_sul_debug_zombies

#define lws_sul_debug_zombies (   _a,
  _b,
  _c,
  _d 
)

Definition at line 273 of file lws-timeout-timer.h.

Typedef Documentation

◆ sul_cb_t

typedef void(* sul_cb_t) (struct lws_sorted_usec_list *sul)

Definition at line 160 of file lws-timeout-timer.h.

◆ lws_sorted_usec_list_t

Enumeration Type Documentation

◆ pending_timeout

Enumerator
NO_PENDING_TIMEOUT 
PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE 
PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE 
PENDING_TIMEOUT_ESTABLISH_WITH_SERVER 
PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE 
PENDING_TIMEOUT_AWAITING_PING 
PENDING_TIMEOUT_CLOSE_ACK 
PENDING_TIMEOUT_UNUSED1 
PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE 
PENDING_TIMEOUT_SSL_ACCEPT 
PENDING_TIMEOUT_HTTP_CONTENT 
PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND 
PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE 
PENDING_TIMEOUT_SHUTDOWN_FLUSH 
PENDING_TIMEOUT_CGI 
PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE 
PENDING_TIMEOUT_WS_PONG_CHECK_SEND_PING 
PENDING_TIMEOUT_WS_PONG_CHECK_GET_PONG 
PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD 
PENDING_TIMEOUT_AWAITING_SOCKS_GREETING_REPLY 
PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY 
PENDING_TIMEOUT_AWAITING_SOCKS_AUTH_REPLY 
PENDING_TIMEOUT_KILLED_BY_SSL_INFO 
PENDING_TIMEOUT_KILLED_BY_PARENT 
PENDING_TIMEOUT_CLOSE_SEND 
PENDING_TIMEOUT_HOLDING_AH 
PENDING_TIMEOUT_UDP_IDLE 
PENDING_TIMEOUT_CLIENT_CONN_IDLE 
PENDING_TIMEOUT_LAGGING 
PENDING_TIMEOUT_THREADPOOL 
PENDING_TIMEOUT_THREADPOOL_TASK 
PENDING_TIMEOUT_KILLED_BY_PROXY_CLIENT_CLOSE 
PENDING_TIMEOUT_USER_OK 
PENDING_TIMEOUT_USER_REASON_BASE 

Definition at line 40 of file lws-timeout-timer.h.

40  {
74 
75  /****** add new things just above ---^ ******/
76 
78 };
@ PENDING_TIMEOUT_THREADPOOL_TASK
@ PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE
@ PENDING_TIMEOUT_ESTABLISH_WITH_SERVER
@ PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE
@ PENDING_TIMEOUT_SHUTDOWN_FLUSH
@ PENDING_TIMEOUT_CLIENT_CONN_IDLE
@ PENDING_TIMEOUT_KILLED_BY_PARENT
@ PENDING_TIMEOUT_AWAITING_PING
@ PENDING_TIMEOUT_USER_OK
@ PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE
@ PENDING_TIMEOUT_THREADPOOL
@ PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE
@ PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE
@ PENDING_TIMEOUT_USER_REASON_BASE
@ PENDING_TIMEOUT_WS_PONG_CHECK_GET_PONG
@ NO_PENDING_TIMEOUT
@ PENDING_TIMEOUT_CGI
@ PENDING_TIMEOUT_SSL_ACCEPT
@ PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD
@ PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY
@ PENDING_TIMEOUT_CLOSE_SEND
@ PENDING_TIMEOUT_UDP_IDLE
@ PENDING_TIMEOUT_HOLDING_AH
@ PENDING_TIMEOUT_AWAITING_SOCKS_AUTH_REPLY
@ PENDING_TIMEOUT_WS_PONG_CHECK_SEND_PING
@ PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND
@ PENDING_TIMEOUT_CLOSE_ACK
@ PENDING_TIMEOUT_UNUSED1
@ PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE
@ PENDING_TIMEOUT_LAGGING
@ PENDING_TIMEOUT_KILLED_BY_SSL_INFO
@ PENDING_TIMEOUT_AWAITING_SOCKS_GREETING_REPLY
@ PENDING_TIMEOUT_HTTP_CONTENT
@ PENDING_TIMEOUT_KILLED_BY_PROXY_CLIENT_CLOSE

Function Documentation

◆ lws_set_timeout()

LWS_VISIBLE LWS_EXTERN void lws_set_timeout ( struct lws *  wsi,
enum pending_timeout  reason,
int  secs 
)

lws_set_timeout() - marks the wsi as subject to a timeout some seconds hence

Parameters
wsiWebsocket connection instance
reasontimeout reason
secshow many seconds. You may set to LWS_TO_KILL_ASYNC to force the connection to timeout at the next opportunity, or LWS_TO_KILL_SYNC to close it synchronously if you know the wsi is not the one currently being serviced.

◆ lws_set_timeout_us()

void lws_set_timeout_us ( struct lws *  wsi,
enum pending_timeout  reason,
lws_usec_t  us 
)

lws_set_timeout_us() - marks the wsi as subject to a timeout some us hence

Parameters
wsiWebsocket connection instance
reasontimeout reason
us0 removes the timeout, otherwise number of us to wait

Higher-resolution version of lws_set_timeout(). Actual resolution depends on platform and load, usually ms.

◆ lws_set_timer_usecs()

LWS_VISIBLE LWS_EXTERN void lws_set_timer_usecs ( struct lws *  wsi,
lws_usec_t  usecs 
)

lws_set_timer_usecs() - schedules a callback on the wsi in the future

Parameters
wsiWebsocket connection instance
usecsLWS_SET_TIMER_USEC_CANCEL removes any existing scheduled callback, otherwise number of microseconds in the future the callback will occur at.

NOTE: event loop support for this:

default poll() loop: yes libuv event loop: yes libev: not implemented (patch welcome) libevent: not implemented (patch welcome)

After the deadline expires, the wsi will get a callback of type LWS_CALLBACK_TIMER and the timer is exhausted. The deadline may be continuously deferred by further calls to lws_set_timer_usecs() with a later deadline, or cancelled by lws_set_timer_usecs(wsi, -1).

If the timer should repeat, lws_set_timer_usecs() must be called again from LWS_CALLBACK_TIMER.

Accuracy depends on the platform and the load on the event loop or system... all that's guaranteed is the callback will come after the requested wait period.

◆ lws_sul2_schedule()

LWS_VISIBLE LWS_EXTERN void lws_sul2_schedule ( struct lws_context *  context,
int  tsi,
int  flags,
lws_sorted_usec_list_t sul 
)

◆ lws_sul_cancel()

LWS_VISIBLE LWS_EXTERN void lws_sul_cancel ( lws_sorted_usec_list_t sul)

◆ lws_sul_earliest_wakeable_event()

LWS_VISIBLE LWS_EXTERN int lws_sul_earliest_wakeable_event ( struct lws_context *  ctx,
lws_usec_t pearliest 
)

◆ lws_sul_schedule()

LWS_VISIBLE LWS_EXTERN void lws_sul_schedule ( struct lws_context *  ctx,
int  tsi,
lws_sorted_usec_list_t sul,
sul_cb_t  _cb,
lws_usec_t  _us 
)

◆ lws_sul_schedule_wakesuspend()

LWS_VISIBLE LWS_EXTERN void lws_sul_schedule_wakesuspend ( struct lws_context *  ctx,
int  tsi,
lws_sorted_usec_list_t sul,
sul_cb_t  _cb,
lws_usec_t  _us 
)

◆ lws_validity_confirmed()

LWS_VISIBLE LWS_EXTERN void lws_validity_confirmed ( struct lws *  wsi)

◆ __lws_sul_insert()

LWS_VISIBLE LWS_EXTERN int __lws_sul_insert ( lws_dll2_owner_t own,
lws_sorted_usec_list_t sul 
)

◆ __lws_sul_service_ripe()

LWS_VISIBLE LWS_EXTERN lws_usec_t __lws_sul_service_ripe ( lws_dll2_owner_t own,
int  own_len,
lws_usec_t  usnow 
)