HttpRequest: close the connection on Stop()
When calling Stop(), we expect the request thread to exit as soon as possible. Closing the connection unlocks it from any blocking read() or write(), avoiding some lockup situations.
This commit is contained in:
parent
f8da8f3477
commit
5b53e2e516
@ -47,6 +47,7 @@ public:
|
||||
const ssize_t size = -1);
|
||||
void AdoptHeaders(BHttpHeaders* const headers);
|
||||
|
||||
status_t Stop();
|
||||
const BUrlResult& Result() const;
|
||||
const char* StatusString(status_t threadStatus) const;
|
||||
|
||||
|
@ -257,6 +257,15 @@ BHttpRequest::Result() const
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BHttpRequest::Stop()
|
||||
{
|
||||
fSocket->Disconnect();
|
||||
// Unlock any pending connect, read or write operation.
|
||||
return BUrlRequest::Stop();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BHttpRequest::_ResetOptions()
|
||||
{
|
||||
@ -880,12 +889,12 @@ BHttpRequest::_SendHeaders()
|
||||
for (BNetworkCookieJar::UrlIterator it
|
||||
= fContext->GetCookieJar().GetUrlIterator(fUrl);
|
||||
(cookie = it.Next()) != NULL;) {
|
||||
cookieString << "; ";
|
||||
cookieString << cookie->RawCookie(false);
|
||||
cookieString << "; ";
|
||||
}
|
||||
|
||||
// Remove the extra "; " we added before the first item
|
||||
cookieString.Remove(0, 2);
|
||||
// Remove the extra "; " we added after the last item.
|
||||
cookieString.Truncate(cookieString.Length() - 2);
|
||||
|
||||
if (cookieString.Length() > 0)
|
||||
fOutputHeaders.AddHeader("Cookie", cookieString);
|
||||
@ -897,6 +906,8 @@ BHttpRequest::_SendHeaders()
|
||||
const char* header = fOutputHeaders.HeaderAt(headerIndex).Header();
|
||||
fSocket->Write(header, strlen(header));
|
||||
fSocket->Write("\r\n", 2);
|
||||
|
||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_HEADER_OUT, "%s", header);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user