c - G-WAN persist request data in handler -
solution:
int session = (int)get_env(argv, session_id);
identifier unique connection us_vhost_data
(vhost) or us_handler_data
(listener) or us_server_data
(server) data persistent > current connection
missing pieces:
- either persistent data connection only
- or way execute code when current connection closed client (econnreset etc.) or server (e.g. kalive_tmo reached)
this should solvable new hdl_before_close state handlers added, makes question answered me.
original question:
is possible in g-wan handler store information persistent request/connection (don't know if "request" applies here)?
to better illustrate mean, got now:
- client (browser, javascript) sends websocket handshake
- handler starts, gets into:
- hdl_after_accept - here call gc_init us_request_data, , no error
- hdl_after_read - here check us_request_data not yet set, websocket handshake , gc_malloc + set us_request_data, increase kalive_tmo, , return 2 send data
- client sees websocket connection being established, (manually triggered seconds afterwards) send message
- handler goes hdl_after_read again, but us_request_data not set
what i've tried: returning 1 instead of 2 in hdl_after_read -> client gets 404 , handshake not work
at moment i'm using us_request_data identify if websocket connection established , next incoming data should in websocket message format, if there different (maybe better?) solution, i'm open of course.
thanks!
edit: added clarification request/connection
i not sure why us_request_data
not seem keep allocated block of memory.
can try persistence.c example see if works expected you?
other g-wan persistent pointers, can use os services linux shared memory api, etc.
but g-wan api should work fine once copy & paste example above.
other values have different scopes:
- us_vhost_data (scope:vhost)
- us_handler_data (scope:listener)
- us_server_data (scope:server)
use session id below unique each connection:
int session = (int)get_env(argv, session_id);
Comments
Post a Comment