Various fixes to Services Kit
* Remove useless dummy protocol loop in UrlRequest * Stop HTTP requests before deleting the socket and other things the loop may still be using * Deletion of items from the authentication map wasn't working * Remove some debug traces
This commit is contained in:
@@ -47,7 +47,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static int32 _ThreadEntry(void* arg);
|
static int32 _ThreadEntry(void* arg);
|
||||||
virtual status_t _ProtocolLoop();
|
virtual status_t _ProtocolLoop() = 0;
|
||||||
virtual void _EmitDebug(BUrlProtocolDebugMessage type,
|
virtual void _EmitDebug(BUrlProtocolDebugMessage type,
|
||||||
const char* format, ...);
|
const char* format, ...);
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ BHttpRequest::BHttpRequest(const BUrl& url, bool ssl, const char* protocolName,
|
|||||||
|
|
||||||
BHttpRequest::~BHttpRequest()
|
BHttpRequest::~BHttpRequest()
|
||||||
{
|
{
|
||||||
|
Stop();
|
||||||
|
|
||||||
delete fSocket;
|
delete fSocket;
|
||||||
|
|
||||||
delete fOptInputData;
|
delete fOptInputData;
|
||||||
@@ -550,7 +552,6 @@ BHttpRequest::_MakeRequest()
|
|||||||
ssize_t bytesTotal = 0;
|
ssize_t bytesTotal = 0;
|
||||||
char* inputTempBuffer = NULL;
|
char* inputTempBuffer = NULL;
|
||||||
ssize_t chunkSize = -1;
|
ssize_t chunkSize = -1;
|
||||||
fQuit = false;
|
|
||||||
|
|
||||||
while (!fQuit && !(receiveEnd && parseEnd)) {
|
while (!fQuit && !(receiveEnd && parseEnd)) {
|
||||||
if (!receiveEnd) {
|
if (!receiveEnd) {
|
||||||
@@ -560,8 +561,7 @@ BHttpRequest::_MakeRequest()
|
|||||||
|
|
||||||
if (bytesRead < 0) {
|
if (bytesRead < 0) {
|
||||||
readError = true;
|
readError = true;
|
||||||
fQuit = true;
|
break;
|
||||||
continue;
|
|
||||||
} else if (bytesRead == 0)
|
} else if (bytesRead == 0)
|
||||||
receiveEnd = true;
|
receiveEnd = true;
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ BUrlContext::BUrlContext()
|
|||||||
fAuthenticationMap(NULL)
|
fAuthenticationMap(NULL)
|
||||||
{
|
{
|
||||||
fAuthenticationMap = new(std::nothrow) BHttpAuthenticationMap();
|
fAuthenticationMap = new(std::nothrow) BHttpAuthenticationMap();
|
||||||
if(!fAuthenticationMap)
|
|
||||||
return;
|
|
||||||
// This is the default authentication, used when nothing else is found.
|
// This is the default authentication, used when nothing else is found.
|
||||||
// The empty string used as a key will match all the domain strings, once
|
// The empty string used as a key will match all the domain strings, once
|
||||||
// we have removed all components.
|
// we have removed all components.
|
||||||
@@ -35,7 +34,7 @@ BUrlContext::~BUrlContext()
|
|||||||
BHttpAuthenticationMap::Iterator iterator =
|
BHttpAuthenticationMap::Iterator iterator =
|
||||||
fAuthenticationMap->GetIterator();
|
fAuthenticationMap->GetIterator();
|
||||||
while(iterator.HasNext())
|
while(iterator.HasNext())
|
||||||
delete iterator.Remove().value;
|
delete *iterator.NextValue();
|
||||||
|
|
||||||
delete fAuthenticationMap;
|
delete fAuthenticationMap;
|
||||||
}
|
}
|
||||||
@@ -59,10 +58,15 @@ BUrlContext::AddAuthentication(const BUrl& url,
|
|||||||
domain += url.Path();
|
domain += url.Path();
|
||||||
BPrivate::HashString hostHash(domain.String(), domain.Length());
|
BPrivate::HashString hostHash(domain.String(), domain.Length());
|
||||||
|
|
||||||
delete fAuthenticationMap->Get(hostHash);
|
BHttpAuthentication* previous = fAuthenticationMap->Get(hostHash);
|
||||||
// Make sure we don't leak memory by overriding a previous
|
|
||||||
// authentication for the same domain.
|
// Make sure we don't leak memory by overriding a previous
|
||||||
fAuthenticationMap->Put(hostHash, authentication);
|
// authentication for the same domain.
|
||||||
|
if(authentication != previous) {
|
||||||
|
fAuthenticationMap->Put(hostHash, authentication);
|
||||||
|
// replaces the old one
|
||||||
|
delete previous;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,11 +29,8 @@ BUrlProtocolRoster::MakeRequest(const BUrl& url,
|
|||||||
return new(std::nothrow) BHttpRequest(url, true, "HTTPS", listener,
|
return new(std::nothrow) BHttpRequest(url, true, "HTTPS", listener,
|
||||||
context);
|
context);
|
||||||
} else if (url.Protocol() == "file") {
|
} else if (url.Protocol() == "file") {
|
||||||
puts("*** FILE URL");
|
|
||||||
return new(std::nothrow) BFileRequest(url, listener, context);
|
return new(std::nothrow) BFileRequest(url, listener, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
puts("*** UNKNOWN protocol");
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,17 +231,6 @@ BUrlRequest::_ThreadEntry(void* arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
BUrlRequest::_ProtocolLoop()
|
|
||||||
{
|
|
||||||
// Dummy _ProtocolLoop
|
|
||||||
while (!fQuit)
|
|
||||||
snooze(1000);
|
|
||||||
|
|
||||||
return B_PROT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BUrlRequest::_EmitDebug(BUrlProtocolDebugMessage type,
|
BUrlRequest::_EmitDebug(BUrlProtocolDebugMessage type,
|
||||||
const char* format, ...)
|
const char* format, ...)
|
||||||
|
|||||||
Reference in New Issue
Block a user