Domanda

Solution:

int session = (int)get_env(argv, SESSION_ID); to get identifier unique to connection US_VHOST_DATA (vhost) or US_HANDLER_DATA (listener) or US_SERVER_DATA (server) for data persistent > current connection

Missing pieces:

  • either persistent data for connection only
  • or some way to execute code when current connection is closed by client (econnreset etc.) or server (e.g. kalive_tmo reached)

This should be solvable as soon as a new HDL_BEFORE_CLOSE state for handlers is added, which makes this question answered for me.


Original Question:

Is it possible in a G-WAN handler to store information persistent to a request/connection (don't really know if "request" applies here)?

To better illustrate what I mean, this is what I got now:

  • Client (browser, javascript) sends websocket handshake
  • Handler starts, gets into:
    • HDL_AFTER_ACCEPT - here i call gc_init for US_REQUEST_DATA, and get no error
    • HDL_AFTER_READ - here i check for US_REQUEST_DATA which is not yet set, so I do websocket handshake and gc_malloc + set US_REQUEST_DATA, increase KALIVE_TMO, and then return 2 to send data
  • Client sees websocket connection as being established, so I (manually triggered some seconds afterwards) send a message
  • Handler goes to HDL_AFTER_READ again, BUT US_REQUEST_DATA is not set

What I've also tried: returning 1 instead of 2 in HDL_AFTER_READ -> client gets 404 and handshake does not work

At the moment I'm only using US_REQUEST_DATA to identify if websocket connection is already established and next incoming data should be in websocket message format, so if there is a different (maybe better?) solution, I'm open to that as well of course.

Thanks!

Edit: Added clarification about request/connection

È stato utile?

Soluzione

I am not sure why US_REQUEST_DATA does not seem to keep your allocated block of memory.

Can you try the persistence.c example to see if it works as expected for you?

Other than G-WAN persistent pointers, you can use OS services like the Linux shared memory API, etc.

But the G-WAN API should work fine once you copy & paste the example above.

Other values have different scopes:

  • US_VHOST_DATA (scope:vhost)
  • US_HANDLER_DATA (scope:listener)
  • US_SERVER_DATA (scope:server)

Use the session ID below which is unique to each CONNECTION:

int session = (int)get_env(argv, SESSION_ID); 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top