Begin work on AsyncFileReader demo
This commit is contained in:
+13
-2
@@ -135,6 +135,8 @@ private:
|
||||
/* Handle HTTP write out */
|
||||
static_dispatch(us_ssl_socket_context_on_writable, us_socket_context_on_writable)(getSocketContext(), [](auto *s) {
|
||||
|
||||
std::cout << "Writable event!" << std::endl;
|
||||
|
||||
/* Silence any spurious writable events due to SSL_read failing to write */
|
||||
AsyncSocket<SSL> *asyncSocket = (AsyncSocket<SSL> *) s;
|
||||
HttpResponseData<SSL> *httpResponseData = (HttpResponseData<SSL> *) asyncSocket->getExt();
|
||||
@@ -162,8 +164,17 @@ private:
|
||||
|
||||
if (httpResponseData->outStream) {
|
||||
/* Regular path, request more data */
|
||||
auto [msg_more, chunk] = httpResponseData->outStream(httpResponseData->offset);
|
||||
httpResponseData->offset += asyncSocket->mergeDrain(chunk);
|
||||
|
||||
// todo: share this path with HttpResponse::write (it is exatly the same logic!)
|
||||
while (true) {
|
||||
auto [msg_more, chunk] = httpResponseData->outStream(httpResponseData->offset);
|
||||
int written = asyncSocket->mergeDrain(chunk);
|
||||
httpResponseData->offset += written;
|
||||
// this is not correct, we can reach the end!
|
||||
if (written < chunk.length()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// todo: we should loop until we cannot send anymore just like we do in HttpResponse::write(stream)!
|
||||
} else {
|
||||
|
||||
@@ -17,6 +17,9 @@ const std::pair<bool, std::string_view> HTTP_STREAM_PAUSE = {false, std::string_
|
||||
/* Return this from a stream callback to signal FIN */
|
||||
const std::pair<bool, std::string_view> HTTP_STREAM_FIN = {false, std::string_view((const char *) 1, 0)};
|
||||
|
||||
/* Nobody cares what value this one has */
|
||||
const auto HTTP_STREAM_IGNORE = HTTP_STREAM_FIN;
|
||||
|
||||
template <bool SSL>
|
||||
struct HttpResponse : public AsyncSocket<SSL> {
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user