blob: 0cfb07a8d7b2cbb67885e97f4c834bb29ce3404f [file] [log] [blame]
Andy Green6c1f64e2013-01-20 11:28:06 +08001Daemonization
2-------------
3
4There's a helper api lws_daemonize built by default that does everything you
5need to daemonize well, including creating a lock file. If you're making
6what's basically a daemon, just call this early in your init to fork to a
7headless background process and exit the starting process.
8
9Notice stdout, stderr, stdin are all redirected to /dev/null to enforce your
10daemon is headless, so you'll need to sort out alternative logging, by, eg,
11syslog.
12
13
14Maximum number of connections
15-----------------------------
16
17The maximum number of connections the library can deal with is decided when
18it starts by querying the OS to find out how many file descriptors it is
19allowed to open (1024 on Fedora for example). It then allocates arrays that
20allow up to that many connections, minus whatever other file descriptors are
21in use by the user code.
22
23If you want to restrict that allocation, or increase it, you can use ulimit or
24similar to change the avaiable number of file descriptors, and when restarted
25libwebsockets will adapt accordingly.
26
27
28Fragmented messages
29-------------------
30
31To support fragmented messages you need to check for the final
32frame of a message with libwebsocket_is_final_fragment. This
33check can be combined with libwebsockets_remaining_packet_payload
34to gather the whole contents of a message, eg:
35
36 case LWS_CALLBACK_RECEIVE:
37 {
38 Client * const client = (Client *)user;
39 const size_t remaining = libwebsockets_remaining_packet_payload(wsi);
40
41 if (!remaining && libwebsocket_is_final_fragment(wsi)) {
42 if (client->HasFragments()) {
43 client->AppendMessageFragment(in, len, 0);
44 in = (void *)client->GetMessage();
45 len = client->GetMessageLength();
46 }
47
48 client->ProcessMessage((char *)in, len, wsi);
49 client->ResetMessage();
50 } else
51 client->AppendMessageFragment(in, len, remaining);
52 }
53 break;
54
55The test app llibwebsockets-test-fraggle sources also show how to
56deal with fragmented messages.
57
58Debug Logging
59-------------
60
61Also using lws_set_log_level api you may provide a custom callback to actually
62emit the log string. By default, this points to an internal emit function
63that sends to stderr. Setting it to NULL leaves it as it is instead.
64
65A helper function lwsl_emit_syslog() is exported from the library to simplify
66logging to syslog. You still need to use setlogmask, openlog and closelog
67in your user code.
68
69The logging apis are made available for user code.
70
71lwsl_err(...)
72lwsl_warn(...)
73lwsl_notice(...)
74lwsl_info(...)
75lwsl_debug(...)
76
77The difference between notice and info is that notice will be logged by default
78whereas info is ignored by default.
79
80
81External Polling Loop support
82-----------------------------
83
84libwebsockets maintains an internal poll() array for all of its
85sockets, but you can instead integrate the sockets into an
86external polling array. That's needed if libwebsockets will
87cooperate with an existing poll array maintained by another
88server.
89
90Four callbacks LWS_CALLBACK_ADD_POLL_FD, LWS_CALLBACK_DEL_POLL_FD,
91LWS_CALLBACK_SET_MODE_POLL_FD and LWS_CALLBACK_CLEAR_MODE_POLL_FD
92appear in the callback for protocol 0 and allow interface code to
93manage socket descriptors in other poll loops.
94
95