Pass "last" bool to res->onData

This commit is contained in:
Alex Hultman
2019-01-07 03:05:19 +01:00
parent 4fde553d03
commit 47467ab1e5
4 changed files with 12 additions and 13 deletions
+2 -2
View File
@@ -168,9 +168,9 @@ private:
/* Continue parsing */
return s;
}, [httpResponseData](void *user, std::string_view data) -> void * {
}, [httpResponseData](void *user, std::string_view data, bool fin) -> void * {
if (httpResponseData->inStream) {
httpResponseData->inStream(data);
httpResponseData->inStream(data, fin);
/* Was the socket closed? */
if (us_socket_is_closed((struct us_socket *) user)) {
+7 -7
View File
@@ -127,7 +127,7 @@ private:
// the only caller of getHeaders
template <int CONSUME_MINIMALLY>
std::pair<int, void *> fenceAndConsumePostPadded(char *data, int length, void *user, HttpRequest *req, std::function<void *(void *, HttpRequest *)> &requestHandler, std::function<void *(void *, std::string_view)> &dataHandler) {
std::pair<int, void *> fenceAndConsumePostPadded(char *data, int length, void *user, HttpRequest *req, std::function<void *(void *, HttpRequest *)> &requestHandler, std::function<void *(void *, std::string_view, bool)> &dataHandler) {
int consumedTotal = 0;
data[length] = '\r';
@@ -161,7 +161,7 @@ private:
if (!CONSUME_MINIMALLY) {
int emittable = std::min(remainingStreamingBytes, length);
dataHandler(user, std::string_view(data, emittable));
dataHandler(user, std::string_view(data, emittable), length == remainingStreamingBytes);
remainingStreamingBytes -= emittable;
data += emittable;
@@ -180,7 +180,7 @@ private:
public:
// todo: what can we do with the socket inside the handlers? we need to check on return from any handler if we closed or terminated or upgraded the socket
void *consumePostPadded(char *data, int length, void *user, std::function<void *(void *, HttpRequest *)> &&requestHandler, std::function<void *(void *, std::string_view)> &&dataHandler, std::function<void *(void *)> &&errorHandler) {
void *consumePostPadded(char *data, int length, void *user, std::function<void *(void *, HttpRequest *)> &&requestHandler, std::function<void *(void *, std::string_view, bool)> &&dataHandler, std::function<void *(void *)> &&errorHandler) {
HttpRequest req;
@@ -188,11 +188,11 @@ public:
// this is exactly the same as below!
if (remainingStreamingBytes >= length) {
void *returnedUser = dataHandler(user, std::string_view(data, length));
void *returnedUser = dataHandler(user, std::string_view(data, length), false);
remainingStreamingBytes -= length;
return returnedUser;
} else {
void *returnedUser = dataHandler(user, std::string_view(data, remainingStreamingBytes));
void *returnedUser = dataHandler(user, std::string_view(data, remainingStreamingBytes), true);
data += remainingStreamingBytes;
length -= remainingStreamingBytes;
@@ -228,11 +228,11 @@ public:
if (remainingStreamingBytes) {
// this is exactly the same as above!
if (remainingStreamingBytes >= length) {
void *returnedUser = dataHandler(user, std::string_view(data, length));
void *returnedUser = dataHandler(user, std::string_view(data, length), false);
remainingStreamingBytes -= length;
return returnedUser;
} else {
void *returnedUser = dataHandler(user, std::string_view(data, remainingStreamingBytes));
void *returnedUser = dataHandler(user, std::string_view(data, remainingStreamingBytes), true);
data += remainingStreamingBytes;
length -= remainingStreamingBytes;
+2 -3
View File
@@ -243,9 +243,8 @@ public:
return this;
}
// onData(chunk, remaining == -1 or 0 or actual remaining)?
/* Attach a read handler for data sent. Will be called with a chunk of size 0 when FIN */
void read(std::function<void(std::string_view)> handler) {
/* Attach a read handler for data sent. Will be called with FIN set true if last segment. */
void onData(std::function<void(std::string_view, bool)> handler) {
HttpResponseData<SSL> *data = getHttpResponseData();
data->inStream = handler;
}
+1 -1
View File
@@ -44,7 +44,7 @@ private:
std::function<void()> onAborted;
//std::function<void()> onData;
std::function<void(std::string_view)> inStream;
std::function<void(std::string_view, bool)> inStream;
std::function<std::pair<bool, std::string_view>(int)> outStream;
/* Outgoing offset */
int offset = 0;