xref: /aosp_15_r20/external/libwebsockets/READMEs/README.h2-long-poll.md (revision 1c60b9aca93fdbc9b5f19b2d2194c91294b22281)
1*1c60b9acSAndroid Build Coastguard Worker# h2 long poll in lws
2*1c60b9acSAndroid Build Coastguard Worker
3*1c60b9acSAndroid Build Coastguard Workerlws server and client can support "immortal" streams that are
4*1c60b9acSAndroid Build Coastguard Workernot subject to normal timeouts under a special condition.  These
5*1c60b9acSAndroid Build Coastguard Workerare read-only (to the client).
6*1c60b9acSAndroid Build Coastguard Worker
7*1c60b9acSAndroid Build Coastguard WorkerNetwork connections that contain at least one immortal stream
8*1c60b9acSAndroid Build Coastguard Workerare themselves not subject to timeouts until the last immortal
9*1c60b9acSAndroid Build Coastguard Workerstream they are carrying closes.
10*1c60b9acSAndroid Build Coastguard Worker
11*1c60b9acSAndroid Build Coastguard WorkerBecause of this, it's recommended there is some other way of
12*1c60b9acSAndroid Build Coastguard Workerconfirming that the client is still active.
13*1c60b9acSAndroid Build Coastguard Worker
14*1c60b9acSAndroid Build Coastguard Worker## Setting up lws server for h2 long poll
15*1c60b9acSAndroid Build Coastguard Worker
16*1c60b9acSAndroid Build Coastguard WorkerVhosts that wish to allow clients to serve these immortal
17*1c60b9acSAndroid Build Coastguard Workerstreams need to set the info.options flag `LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL`
18*1c60b9acSAndroid Build Coastguard Workerat vhost creation time.  The JSON config equivalent is to set
19*1c60b9acSAndroid Build Coastguard Worker
20*1c60b9acSAndroid Build Coastguard Worker```
21*1c60b9acSAndroid Build Coastguard Worker"h2-half-closed-long-poll": "1"
22*1c60b9acSAndroid Build Coastguard Worker```
23*1c60b9acSAndroid Build Coastguard Worker
24*1c60b9acSAndroid Build Coastguard Workeron the vhost.  That's all that is needed.
25*1c60b9acSAndroid Build Coastguard Worker
26*1c60b9acSAndroid Build Coastguard WorkerStreams continue to act normally for timeout with the exception
27*1c60b9acSAndroid Build Coastguard Workerclient streams are allowed to signal they are half-closing by
28*1c60b9acSAndroid Build Coastguard Workersending a zero-length DATA frame with END_STREAM set.  These
29*1c60b9acSAndroid Build Coastguard Workerstreams are allowed to exist outside of any timeout and data
30*1c60b9acSAndroid Build Coastguard Workercan be sent on them at will in the server -> client direction.
31*1c60b9acSAndroid Build Coastguard Worker
32*1c60b9acSAndroid Build Coastguard Worker## Setting client streams for long poll
33*1c60b9acSAndroid Build Coastguard Worker
34*1c60b9acSAndroid Build Coastguard WorkerAn API is provided to allow established h2 client streams to
35*1c60b9acSAndroid Build Coastguard Workertransition to immortal mode and send the END_STREAM to the server
36*1c60b9acSAndroid Build Coastguard Workerto indicate it.
37*1c60b9acSAndroid Build Coastguard Worker
38*1c60b9acSAndroid Build Coastguard Worker```
39*1c60b9acSAndroid Build Coastguard Workerint
40*1c60b9acSAndroid Build Coastguard Workerlws_h2_client_stream_long_poll_rxonly(struct lws *wsi);
41*1c60b9acSAndroid Build Coastguard Worker```
42*1c60b9acSAndroid Build Coastguard Worker
43*1c60b9acSAndroid Build Coastguard Worker## Example applications
44*1c60b9acSAndroid Build Coastguard Worker
45*1c60b9acSAndroid Build Coastguard WorkerYou can confirm the long poll flow simply using example applications.
46*1c60b9acSAndroid Build Coastguard WorkerBuild and run `http-server/minimal-http-server-h2-long-poll` in one
47*1c60b9acSAndroid Build Coastguard Workerterminal.
48*1c60b9acSAndroid Build Coastguard Worker
49*1c60b9acSAndroid Build Coastguard WorkerIn another, build the usual `http-client/minimal-http-client` example
50*1c60b9acSAndroid Build Coastguard Workerand run it with the flags `-l --long-poll`
51*1c60b9acSAndroid Build Coastguard Worker
52*1c60b9acSAndroid Build Coastguard WorkerThe client will connect to the server and transition to the immortal mode.
53*1c60b9acSAndroid Build Coastguard WorkerThe server sends a timestamp every minute to the client, and that will
54*1c60b9acSAndroid Build Coastguard Workerstay up without timeouts.
55*1c60b9acSAndroid Build Coastguard Worker
56