CppServer
CppServer copied to clipboard
Can you recommend a technique for deferring a response to another thread?
I'm wondering if you could suggest a strategy to defer a response to another thread. Consider where a response is expensive and needs to be computed. I don't want to block the service threads. Since the onReceivedRequest is a method of HttpSession I can't take a reference to its shared_ptr and ensure it's continued existence if the client closes the other end and the session is disconnected.
I've worked around that by making a subclass of HttpSession that contains a reference to the shared pointer returned by HttpServer::CreateSession(). It's a hack but mostly works.
An additional issue that will result if I'm holding a reference to the session is a race when a client disconnects on timeout and before onDisconnect is called. The deferred response might become available and be written to the file descriptor that has since been opened to a new client, thus passing data to a client unrelated to the original session.
CC: @chronoxor
@chronoxor Is this something you can advise on? I'm also seeing that the project has no PRs open or closed. I wonder how bugs are fixed and improvements being made.
CC: @chronoxor