Begin work on AsyncFileReader demo

This commit is contained in:
Alex Hultman
2018-09-23 20:32:47 +02:00
parent 7f3753e9db
commit 2fb87b67c7
5 changed files with 140 additions and 113 deletions
+13 -2
View File
@@ -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 {
+3
View File
@@ -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: