|
|
@@ -244,11 +244,10 @@ BHttpSession::Impl::Execute(BHttpRequest&& request, std::unique_ptr<BDataIO> tar
|
|
|
|
return retval;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
BHttpSession::Impl::Cancel(int32 identifier)
|
|
|
|
BHttpSession::Impl::Cancel(int32 identifier)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::cout << "BHttpSession::Impl::Cancel for " << identifier << std::endl;
|
|
|
|
|
|
|
|
auto lock = AutoLocker<BLocker>(fLock);
|
|
|
|
auto lock = AutoLocker<BLocker>(fLock);
|
|
|
|
// Check if the item is on the control queue
|
|
|
|
// Check if the item is on the control queue
|
|
|
|
fControlQueue.remove_if([&identifier](auto& request){
|
|
|
|
fControlQueue.remove_if([&identifier](auto& request){
|
|
|
@@ -313,14 +312,11 @@ BHttpSession::Impl::ControlThreadFunc(void* arg)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
for (auto& request: requests) {
|
|
|
|
for (auto& request: requests) {
|
|
|
|
std::cout << "ControlThreadFunc(): processing request " << request.Id() << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool hasError = false;
|
|
|
|
bool hasError = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
request.ResolveHostName();
|
|
|
|
request.ResolveHostName();
|
|
|
|
request.OpenConnection();
|
|
|
|
request.OpenConnection();
|
|
|
|
} catch (...) {
|
|
|
|
} catch (...) {
|
|
|
|
std::cout << "ControlThreadFunc()[" << request.Id() << "] error resolving/connecting" << std::endl;
|
|
|
|
|
|
|
|
request.SetError(std::current_exception());
|
|
|
|
request.SetError(std::current_exception());
|
|
|
|
hasError = true;
|
|
|
|
hasError = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -347,7 +343,6 @@ BHttpSession::Impl::ControlThreadFunc(void* arg)
|
|
|
|
wait_for_thread(impl->fDataThread, &threadResult);
|
|
|
|
wait_for_thread(impl->fDataThread, &threadResult);
|
|
|
|
// Cancel all requests
|
|
|
|
// Cancel all requests
|
|
|
|
for (auto& request: impl->fControlQueue) {
|
|
|
|
for (auto& request: impl->fControlQueue) {
|
|
|
|
std::cout << "ControlThreadFunc()[" << request.Id() << "] canceling request because the session is quitting" << std::endl;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
throw BNetworkRequestError(__PRETTY_FUNCTION__, BNetworkRequestError::Canceled);
|
|
|
|
throw BNetworkRequestError(__PRETTY_FUNCTION__, BNetworkRequestError::Canceled);
|
|
|
|
} catch (...) {
|
|
|
|
} catch (...) {
|
|
|
@@ -382,7 +377,6 @@ BHttpSession::Impl::DataThreadFunc(void* arg)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
else if (status < 0) {
|
|
|
|
else if (status < 0) {
|
|
|
|
// Something went inexplicably wrong
|
|
|
|
// Something went inexplicably wrong
|
|
|
|
std::cout << "BSystemError wait_for_objects() " << status << std::endl;
|
|
|
|
|
|
|
|
throw BSystemError("wait_for_objects()", status);
|
|
|
|
throw BSystemError("wait_for_objects()", status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -422,7 +416,6 @@ BHttpSession::Impl::DataThreadFunc(void* arg)
|
|
|
|
for (auto it = data->connectionMap.cbegin(); it != data->connectionMap.cend(); it++) {
|
|
|
|
for (auto it = data->connectionMap.cbegin(); it != data->connectionMap.cend(); it++) {
|
|
|
|
offset++;
|
|
|
|
offset++;
|
|
|
|
if (it->second.Id() == id) {
|
|
|
|
if (it->second.Id() == id) {
|
|
|
|
std::cout << "DataThreadFunc() [" << id << "] cancelling request" << std::endl;
|
|
|
|
|
|
|
|
data->objectList[offset].events = EVENT_CANCELLED;
|
|
|
|
data->objectList[offset].events = EVENT_CANCELLED;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -442,12 +435,10 @@ BHttpSession::Impl::DataThreadFunc(void* arg)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
if ((item.events & B_EVENT_WRITE) == B_EVENT_WRITE) {
|
|
|
|
if ((item.events & B_EVENT_WRITE) == B_EVENT_WRITE) {
|
|
|
|
auto& request = data->connectionMap.find(item.object)->second;
|
|
|
|
auto& request = data->connectionMap.find(item.object)->second;
|
|
|
|
std::cout << "DataThreadFunc() [" << request.Id() << "] ready for sending the request" << std::endl;
|
|
|
|
|
|
|
|
auto error = false;
|
|
|
|
auto error = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
request.TransferRequest();
|
|
|
|
request.TransferRequest();
|
|
|
|
} catch (...) {
|
|
|
|
} catch (...) {
|
|
|
|
std::cout << "DataThreadFunc() [" << request.Id() << "] error sending the request" << std::endl;
|
|
|
|
|
|
|
|
request.SetError(std::current_exception());
|
|
|
|
request.SetError(std::current_exception());
|
|
|
|
error = true;
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -462,7 +453,6 @@ BHttpSession::Impl::DataThreadFunc(void* arg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ((item.events & B_EVENT_READ) == B_EVENT_READ) {
|
|
|
|
} else if ((item.events & B_EVENT_READ) == B_EVENT_READ) {
|
|
|
|
auto& request = data->connectionMap.find(item.object)->second;
|
|
|
|
auto& request = data->connectionMap.find(item.object)->second;
|
|
|
|
std::cout << "DataThreadFunc() [" << request.Id() << "] ready for receiving the response" << std::endl;
|
|
|
|
|
|
|
|
auto finished = false;
|
|
|
|
auto finished = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (request.CanCancel())
|
|
|
|
if (request.CanCancel())
|
|
|
@@ -471,8 +461,6 @@ BHttpSession::Impl::DataThreadFunc(void* arg)
|
|
|
|
finished = request.ReceiveResult();
|
|
|
|
finished = request.ReceiveResult();
|
|
|
|
} catch (const Redirect& r) {
|
|
|
|
} catch (const Redirect& r) {
|
|
|
|
// Request is redirected, send back to the controlThread
|
|
|
|
// Request is redirected, send back to the controlThread
|
|
|
|
std::cout << "DataThreadFunc() [" << request.Id() << "] will be redirected to " << r.url.UrlString().String() << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Move existing request into a new request and hand over to the control queue
|
|
|
|
// Move existing request into a new request and hand over to the control queue
|
|
|
|
auto lock = AutoLocker<BLocker>(data->fLock);
|
|
|
|
auto lock = AutoLocker<BLocker>(data->fLock);
|
|
|
|
data->fControlQueue.emplace_back(request, r);
|
|
|
|
data->fControlQueue.emplace_back(request, r);
|
|
|
@@ -519,31 +507,29 @@ BHttpSession::Impl::DataThreadFunc(void* arg)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Likely to be B_EVENT_INVALID. This should not happen
|
|
|
|
// Likely to be B_EVENT_INVALID. This should not happen
|
|
|
|
auto& request = data->connectionMap.find(item.object)->second;
|
|
|
|
auto& request = data->connectionMap.find(item.object)->second;
|
|
|
|
std::cout << "DataThreadFunc() [" << request.Id() << "] other event " << item.events << std::endl;
|
|
|
|
request.SendMessage(UrlEvent::DebugMessage, [](BMessage& msg){
|
|
|
|
throw BRuntimeError(__PRETTY_FUNCTION__, "Socket was deleted at an unexpected time");
|
|
|
|
msg.AddUInt32(UrlEventData::DebugType, UrlEventData::DebugError);
|
|
|
|
|
|
|
|
msg.AddString(UrlEventData::DebugMessage, "Unexpected event; socket deleted?");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
throw BRuntimeError(__PRETTY_FUNCTION__,
|
|
|
|
|
|
|
|
"Socket was deleted at an unexpected time");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Reset objectList
|
|
|
|
// Reset objectList
|
|
|
|
data->objectList[0].events = B_EVENT_ACQUIRE_SEMAPHORE;
|
|
|
|
data->objectList[0].events = B_EVENT_ACQUIRE_SEMAPHORE;
|
|
|
|
if (resizeObjectList) {
|
|
|
|
if (resizeObjectList)
|
|
|
|
std::cout << "DataThreadFunc() resizing objectlist to " << data->connectionMap.size() + 1 << std::endl;
|
|
|
|
|
|
|
|
data->objectList.resize(data->connectionMap.size() + 1);
|
|
|
|
data->objectList.resize(data->connectionMap.size() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto i = 1;
|
|
|
|
auto i = 1;
|
|
|
|
for (auto it = data->connectionMap.cbegin(); it != data->connectionMap.cend(); it++) {
|
|
|
|
for (auto it = data->connectionMap.cbegin(); it != data->connectionMap.cend(); it++) {
|
|
|
|
data->objectList[i].object = it->first;
|
|
|
|
data->objectList[i].object = it->first;
|
|
|
|
if (it->second.State() == Request::InitialState) {
|
|
|
|
if (it->second.State() == Request::InitialState)
|
|
|
|
std::cout << "DataThreadFunc() [" << it->second.Id() << "] in Request::InitialState" << std::endl;
|
|
|
|
|
|
|
|
throw BRuntimeError(__PRETTY_FUNCTION__, "Invalid state of request");
|
|
|
|
throw BRuntimeError(__PRETTY_FUNCTION__, "Invalid state of request");
|
|
|
|
}
|
|
|
|
else if (it->second.State() == Request::Connected)
|
|
|
|
else if (it->second.State() == Request::Connected) {
|
|
|
|
|
|
|
|
data->objectList[i].events = B_EVENT_WRITE | B_EVENT_DISCONNECTED;
|
|
|
|
data->objectList[i].events = B_EVENT_WRITE | B_EVENT_DISCONNECTED;
|
|
|
|
std::cout << "DataThreadFunc() [ " << it->second.Id() << "] wait for B_EVENT_WRITE" << std::endl;
|
|
|
|
else
|
|
|
|
} else {
|
|
|
|
|
|
|
|
std::cout << "DataThreadFunc() [ " << it->second.Id() << "] wait for B_EVENT_READ" << std::endl;
|
|
|
|
|
|
|
|
data->objectList[i].events = B_EVENT_READ | B_EVENT_DISCONNECTED;
|
|
|
|
data->objectList[i].events = B_EVENT_READ | B_EVENT_DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -552,14 +538,12 @@ BHttpSession::Impl::DataThreadFunc(void* arg)
|
|
|
|
// Cancel all requests
|
|
|
|
// Cancel all requests
|
|
|
|
for (auto it = data->connectionMap.begin(); it != data->connectionMap.end(); it++) {
|
|
|
|
for (auto it = data->connectionMap.begin(); it != data->connectionMap.end(); it++) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
std::cout << "DataThreadFunc() [ " << it->second.Id() << "] canceling request because we are quitting" << std::endl;
|
|
|
|
|
|
|
|
throw BNetworkRequestError(__PRETTY_FUNCTION__, BNetworkRequestError::Canceled);
|
|
|
|
throw BNetworkRequestError(__PRETTY_FUNCTION__, BNetworkRequestError::Canceled);
|
|
|
|
} catch (...) {
|
|
|
|
} catch (...) {
|
|
|
|
it->second.SetError(std::current_exception());
|
|
|
|
it->second.SetError(std::current_exception());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
std::cout << "DataThreadFunc(): Unknown reason that the dataQueueSem is deleted" << std::endl;
|
|
|
|
|
|
|
|
throw BRuntimeError(__PRETTY_FUNCTION__,
|
|
|
|
throw BRuntimeError(__PRETTY_FUNCTION__,
|
|
|
|
"Unknown reason that the dataQueueSem is deleted");
|
|
|
|
"Unknown reason that the dataQueueSem is deleted");
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -578,7 +562,6 @@ std::vector<BHttpSession::Request>
|
|
|
|
BHttpSession::Impl::GetRequestsForControlThread()
|
|
|
|
BHttpSession::Impl::GetRequestsForControlThread()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::vector<BHttpSession::Request> requests;
|
|
|
|
std::vector<BHttpSession::Request> requests;
|
|
|
|
std::cout << __PRETTY_FUNCTION__ << ": number of items in fConnectionCount: " << fConnectionCount.size() << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Clean up connection list if it is at the max number of hosts
|
|
|
|
// Clean up connection list if it is at the max number of hosts
|
|
|
|
if (fConnectionCount.size() >= fMaxHosts.load()) {
|
|
|
|
if (fConnectionCount.size() >= fMaxHosts.load()) {
|
|
|
@@ -597,10 +580,13 @@ BHttpSession::Impl::GetRequestsForControlThread()
|
|
|
|
auto host = request.GetHost();
|
|
|
|
auto host = request.GetHost();
|
|
|
|
auto it = fConnectionCount.find(host);
|
|
|
|
auto it = fConnectionCount.find(host);
|
|
|
|
if (it != fConnectionCount.end()) {
|
|
|
|
if (it != fConnectionCount.end()) {
|
|
|
|
std::cout << __PRETTY_FUNCTION__ << ": found connnections for host, count: " << it->second << std::endl;
|
|
|
|
|
|
|
|
if (static_cast<size_t>(atomic_get(std::addressof(it->second)))
|
|
|
|
if (static_cast<size_t>(atomic_get(std::addressof(it->second)))
|
|
|
|
>= fMaxConnectionsPerHost.load(std::memory_order_relaxed)) {
|
|
|
|
>= fMaxConnectionsPerHost.load(std::memory_order_relaxed)) {
|
|
|
|
std::cout << "\tskip loading this request as max connections per host is reached" << std::endl;
|
|
|
|
request.SendMessage(UrlEvent::DebugMessage, [](BMessage& msg){
|
|
|
|
|
|
|
|
msg.AddUInt32(UrlEventData::DebugType, UrlEventData::DebugWarning);
|
|
|
|
|
|
|
|
msg.AddString(UrlEventData::DebugMessage,
|
|
|
|
|
|
|
|
"Request is queued: too many active connections for host");
|
|
|
|
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
atomic_add(std::addressof(it->second), 1);
|
|
|
|
atomic_add(std::addressof(it->second), 1);
|
|
|
@@ -608,7 +594,11 @@ BHttpSession::Impl::GetRequestsForControlThread()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (fConnectionCount.size() == fMaxHosts.load()) {
|
|
|
|
if (fConnectionCount.size() == fMaxHosts.load()) {
|
|
|
|
std::cout << "\tskip loading this request as max hosts is reached" << std::endl;
|
|
|
|
request.SendMessage(UrlEvent::DebugMessage, [](BMessage& msg){
|
|
|
|
|
|
|
|
msg.AddUInt32(UrlEventData::DebugType, UrlEventData::DebugWarning);
|
|
|
|
|
|
|
|
msg.AddString(UrlEventData::DebugMessage,
|
|
|
|
|
|
|
|
"Request is queued: maximum number of concurrent hosts");
|
|
|
|
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto[newIt, success] = fConnectionCount.insert({host, 1});
|
|
|
|
auto[newIt, success] = fConnectionCount.insert({host, 1});
|
|
|
@@ -728,6 +718,18 @@ void
|
|
|
|
BHttpSession::Request::SetError(std::exception_ptr e)
|
|
|
|
BHttpSession::Request::SetError(std::exception_ptr e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fResult->SetError(e);
|
|
|
|
fResult->SetError(e);
|
|
|
|
|
|
|
|
SendMessage(UrlEvent::DebugMessage, [&e](BMessage& msg){
|
|
|
|
|
|
|
|
msg.AddUInt32(UrlEventData::DebugType, UrlEventData::DebugError);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
std::rethrow_exception(e);
|
|
|
|
|
|
|
|
} catch (BError& error) {
|
|
|
|
|
|
|
|
msg.AddString(UrlEventData::DebugMessage, error.DebugMessage());
|
|
|
|
|
|
|
|
} catch (std::exception& error) {
|
|
|
|
|
|
|
|
msg.AddString(UrlEventData::DebugMessage, error.what());
|
|
|
|
|
|
|
|
} catch (...) {
|
|
|
|
|
|
|
|
msg.AddString(UrlEventData::DebugMessage, "Unknown exception");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
SendMessage(UrlEvent::RequestCompleted, [](BMessage& msg){
|
|
|
|
SendMessage(UrlEvent::RequestCompleted, [](BMessage& msg){
|
|
|
|
msg.AddBool(UrlEventData::Success, false);
|
|
|
|
msg.AddBool(UrlEventData::Success, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
@@ -819,8 +821,6 @@ BHttpSession::Request::OpenConnection()
|
|
|
|
void
|
|
|
|
void
|
|
|
|
BHttpSession::Request::TransferRequest()
|
|
|
|
BHttpSession::Request::TransferRequest()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::cout << "TransferRequest() [" << Id() << "] Starting sending of request" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assert that we are in the right state
|
|
|
|
// Assert that we are in the right state
|
|
|
|
if (fRequestStatus != Connected)
|
|
|
|
if (fRequestStatus != Connected)
|
|
|
|
throw BRuntimeError(__PRETTY_FUNCTION__,
|
|
|
|
throw BRuntimeError(__PRETTY_FUNCTION__,
|
|
|
@@ -841,10 +841,6 @@ BHttpSession::Request::TransferRequest()
|
|
|
|
|
|
|
|
|
|
|
|
if (fSerializer.Complete())
|
|
|
|
if (fSerializer.Complete())
|
|
|
|
fRequestStatus = RequestSent;
|
|
|
|
fRequestStatus = RequestSent;
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "TransferRequest() [" << Id() << "] currentBytesWritten: " << currentBytesWritten << " totalBytesWritten: " <<
|
|
|
|
|
|
|
|
fSerializer.BodyBytesTransferred() << " totalSize: " << fSerializer.BodyBytesTotal().value_or(0) << " complete: "
|
|
|
|
|
|
|
|
<< fSerializer.Complete() << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -859,11 +855,8 @@ BHttpSession::Request::ReceiveResult()
|
|
|
|
// First: stream data from the socket
|
|
|
|
// First: stream data from the socket
|
|
|
|
auto bytesRead = fBuffer.ReadFrom(fSocket.get());
|
|
|
|
auto bytesRead = fBuffer.ReadFrom(fSocket.get());
|
|
|
|
|
|
|
|
|
|
|
|
if (bytesRead == B_WOULD_BLOCK || bytesRead == B_INTERRUPTED) {
|
|
|
|
if (bytesRead == B_WOULD_BLOCK || bytesRead == B_INTERRUPTED)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "ReceiveResult() [" << Id() << "] read " << bytesRead << " from socket" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Parse the content in the buffer
|
|
|
|
// Parse the content in the buffer
|
|
|
|
switch (fRequestStatus) {
|
|
|
|
switch (fRequestStatus) {
|
|
|
@@ -954,7 +947,6 @@ BHttpSession::Request::ReceiveResult()
|
|
|
|
case BHttpStatusCode::TemporaryRedirect:
|
|
|
|
case BHttpStatusCode::TemporaryRedirect:
|
|
|
|
case BHttpStatusCode::PermanentRedirect:
|
|
|
|
case BHttpStatusCode::PermanentRedirect:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::cout << "ReceiveResult() [" << Id() << "] Handle redirect with status: " << fStatus.code << std::endl;
|
|
|
|
|
|
|
|
auto locationField = fFields.FindField("Location");
|
|
|
|
auto locationField = fFields.FindField("Location");
|
|
|
|
if (locationField == fFields.end()) {
|
|
|
|
if (locationField == fFields.end()) {
|
|
|
|
throw BNetworkRequestError(__PRETTY_FUNCTION__,
|
|
|
|
throw BNetworkRequestError(__PRETTY_FUNCTION__,
|
|
|
@@ -996,7 +988,6 @@ BHttpSession::Request::ReceiveResult()
|
|
|
|
|
|
|
|
|
|
|
|
if (!fParser.HasContent()) {
|
|
|
|
if (!fParser.HasContent()) {
|
|
|
|
// Any requests with not content are finished
|
|
|
|
// Any requests with not content are finished
|
|
|
|
std::cout << "ReceiveResult() [" << Id() << "] Request is completing without content" << std::endl;
|
|
|
|
|
|
|
|
fResult->SetBody();
|
|
|
|
fResult->SetBody();
|
|
|
|
SendMessage(UrlEvent::RequestCompleted, [](BMessage& msg) {
|
|
|
|
SendMessage(UrlEvent::RequestCompleted, [](BMessage& msg) {
|
|
|
|
msg.AddBool(UrlEventData::Success, true);
|
|
|
|
msg.AddBool(UrlEventData::Success, true);
|
|
|
@@ -1016,9 +1007,6 @@ BHttpSession::Request::ReceiveResult()
|
|
|
|
return bytesWrittenToBody;
|
|
|
|
return bytesWrittenToBody;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "ReceiveResult() [" << Id() << "] body bytes current read/total received/total expected: " <<
|
|
|
|
|
|
|
|
bytesRead << "/" << fParser.BodyBytesTransferred() << "/" << fParser.BodyBytesTotal().value_or(0) << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SendMessage(UrlEvent::DownloadProgress, [this, bytesRead](BMessage& msg) {
|
|
|
|
SendMessage(UrlEvent::DownloadProgress, [this, bytesRead](BMessage& msg) {
|
|
|
|
msg.AddInt64(UrlEventData::NumBytes, bytesRead);
|
|
|
|
msg.AddInt64(UrlEventData::NumBytes, bytesRead);
|
|
|
|
if (fParser.BodyBytesTotal())
|
|
|
|
if (fParser.BodyBytesTotal())
|
|
|
@@ -1032,7 +1020,6 @@ BHttpSession::Request::ReceiveResult()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (fParser.Complete()) {
|
|
|
|
if (fParser.Complete()) {
|
|
|
|
std::cout << "ReceiveResult() [" << Id() << "] received all body bytes: " << fParser.BodyBytesTransferred() << std::endl;
|
|
|
|
|
|
|
|
fResult->SetBody();
|
|
|
|
fResult->SetBody();
|
|
|
|
SendMessage(UrlEvent::RequestCompleted, [](BMessage& msg) {
|
|
|
|
SendMessage(UrlEvent::RequestCompleted, [](BMessage& msg) {
|
|
|
|
msg.AddBool(UrlEventData::Success, true);
|
|
|
|
msg.AddBool(UrlEventData::Success, true);
|
|
|
|