Removed the need for clients to explicitly call NET_PollSockets(...). This has been replaced with a timer based polling scheme

This commit is contained in:
rpotts%netscape.com 1998-07-29 06:01:11 +00:00
parent 0d0fbe9d1e
commit 6ed683d129
2 changed files with 66 additions and 2 deletions

View File

@ -17,6 +17,7 @@
*/
#include "nsRepository.h"
#include "nsITimer.h"
#include "nsNetService.h"
#include "nsNetStream.h"
#include "net.h"
@ -36,6 +37,9 @@ extern "C" {
#include "nsINetContainerApplication.h"
/* XXX: Legacy definitions... */
// Global count of active urls from mkgeturl.c
extern "C" int NET_TotalNumberOfProcessingURLs;
MWContext *new_stub_context(URL_Struct *URL_s);
void free_stub_context(MWContext *window_id);
static void bam_exit_routine(URL_Struct *URL_s, int status, MWContext *window_id);
@ -118,7 +122,8 @@ nsNetlibService::nsNetlibService(nsINetContainerApplication *aContainerApp)
NULL,
NET_ChunkedDecoderStream);
mPollingTimer = nsnull;
RL_Init();
mContainer = aContainerApp;
@ -174,7 +179,8 @@ nsNetlibService::~nsNetlibService()
m_stubContext = NULL;
}
*/
NS_IF_RELEASE(mPollingTimer);
NS_IF_RELEASE(mContainer);
NET_ShutdownNetLib();
}
@ -249,6 +255,11 @@ nsresult nsNetlibService::OpenStream(nsIURL *aUrl,
/* Remember, the URL_s may have been freed ! */
/*
* Start the network timer to call NET_PollSockets(...) until the
* URL has been completely loaded...
*/
SchedulePollingTimer();
return NS_OK;
}
@ -342,6 +353,12 @@ nsresult nsNetlibService::OpenBlockingStream(nsIURL *aUrl,
/* Remember, the URL_s may have been freed ! */
/*
* Start the network timer to call NET_PollSockets(...) until the
* URL has been completely loaded...
*/
SchedulePollingTimer();
*aNewStream = pBlockingStream;
return NS_OK;
}
@ -440,6 +457,46 @@ nsNetlibService::SetCookieString(nsIURL *aURL, const nsString& aCookie)
return NS_OK;
}
void nsNetlibService::SchedulePollingTimer()
{
// If a timer is already active, then do not create another...
if (nsnull == mPollingTimer) {
if (NS_OK == NS_NewTimer(&mPollingTimer)) {
mPollingTimer->Init(nsNetlibService::NetPollSocketsCallback, this, 1000 / 50);
}
}
}
void nsNetlibService::CleanupPollingTimer(nsITimer* aTimer)
{
NS_PRECONDITION((aTimer == mPollingTimer), "Unknown Timer...");
NS_RELEASE(mPollingTimer);
}
void nsNetlibService::NetPollSocketsCallback(nsITimer* aTimer, void* aClosure)
{
nsNetlibService* inet = (nsNetlibService*)aClosure;
NS_PRECONDITION((nsnull != inet), "Null pointer");
if (nsnull != inet) {
(void) NET_PollSockets();
inet->CleanupPollingTimer(aTimer);
// Keep scheduling callbacks as long as there are URLs to process...
if (0 < NET_TotalNumberOfProcessingURLs) {
inet->SchedulePollingTimer();
}
}
}
extern "C" {
static nsNetlibService *pNetlib = NULL;

View File

@ -24,6 +24,7 @@
#include "nsINetService.h"
class nsINetContainerApplication;
class nsITimer;
class nsNetlibService : public nsINetService {
@ -47,11 +48,17 @@ public:
protected:
virtual ~nsNetlibService();
void SchedulePollingTimer();
void CleanupPollingTimer(nsITimer* aTimer);
static void NetPollSocketsCallback(nsITimer* aTimer, void* aClosure);
private:
/* XXX: This is temporary until bamwrap.cpp is removed... */
void *m_stubContext;
nsINetContainerApplication *mContainer;
nsIPref *mPref;
nsITimer* mPollingTimer;
};