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:
Adrien Destugues 2014-01-02 08:35:54 +01:00
parent f8da8f3477
commit 5b53e2e516
2 changed files with 15 additions and 3 deletions

View File

@ -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;

View File

@ -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);
}
}