drogonframework / drogonframework/drogon
Support asynchronous HttpResponse::newStreamResponse
- Dominant language
- C++
- Stars
- 14.3k
- Forks
- 1.4k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 15
Description
Currently the handler invoked by HttpResponse::newStreamResponse does not pass in a callback or allow a coroutine task to call the response callback. It directly expects me to write to the response buffer/size in a synchronous/blocking fashion. I want to support asynchronous server-sent event streaming where I deliver push messages via a server-sent text/event-stream endpoint (https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
https://github.com/drogonframework/drogon/pull/1156#issuecomment-1159808923
Described the issue very well here. We need some mechanism to allow throttling inside streaming callbacks because the data to be streamed might not be available just yet. So we want to return a length of 0 but prevent the chunking callback from closing the connection because more data might be available later.
If I use a condition variable and a mutex to accomplish what I want then the server can deadlock because it steals a worker from the drogon/trantor thread pool. What I am looking for is a way to have HttpResponse::newAsyncStreamResponse that gives the stream handler a completion callback that I can invoke once I have more data available instead of requiring me to directly return that data.
Contributor guide
Assessment
This issue has not been assessed yet.