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:38:03 +01:00
parent f8da8f3477
commit 5b53e2e516
2 changed files with 15 additions and 3 deletions
+1
View File
@@ -47,6 +47,7 @@ public:
const ssize_t size = -1); const ssize_t size = -1);
void AdoptHeaders(BHttpHeaders* const headers); void AdoptHeaders(BHttpHeaders* const headers);
status_t Stop();
const BUrlResult& Result() const; const BUrlResult& Result() const;
const char* StatusString(status_t threadStatus) const; const char* StatusString(status_t threadStatus) const;
+14 -3
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 void
BHttpRequest::_ResetOptions() BHttpRequest::_ResetOptions()
{ {
@@ -880,12 +889,12 @@ BHttpRequest::_SendHeaders()
for (BNetworkCookieJar::UrlIterator it for (BNetworkCookieJar::UrlIterator it
= fContext->GetCookieJar().GetUrlIterator(fUrl); = fContext->GetCookieJar().GetUrlIterator(fUrl);
(cookie = it.Next()) != NULL;) { (cookie = it.Next()) != NULL;) {
cookieString << "; ";
cookieString << cookie->RawCookie(false); cookieString << cookie->RawCookie(false);
cookieString << "; ";
} }
// Remove the extra "; " we added before the first item // Remove the extra "; " we added after the last item.
cookieString.Remove(0, 2); cookieString.Truncate(cookieString.Length() - 2);
if (cookieString.Length() > 0) if (cookieString.Length() > 0)
fOutputHeaders.AddHeader("Cookie", cookieString); fOutputHeaders.AddHeader("Cookie", cookieString);
@@ -897,6 +906,8 @@ BHttpRequest::_SendHeaders()
const char* header = fOutputHeaders.HeaderAt(headerIndex).Header(); const char* header = fOutputHeaders.HeaderAt(headerIndex).Header();
fSocket->Write(header, strlen(header)); fSocket->Write(header, strlen(header));
fSocket->Write("\r\n", 2); fSocket->Write("\r\n", 2);
_EmitDebug(B_URL_PROTOCOL_DEBUG_HEADER_OUT, "%s", header);
} }
} }