Fix to shutdown socket transport service. DNS service too. Bug #21124 r=valeski

This commit is contained in:
warren%netscape.com 2000-01-19 07:58:40 +00:00
Родитель 6dab31d4a3
Коммит d353634848
6 изменённых файлов: 101 добавлений и 49 удалений

Просмотреть файл

@ -47,6 +47,9 @@
#define NS_ERROR_IN_PROGRESS \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 15)
#define NS_ERROR_OFFLINE \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 16)
// internal unknown content-type
//
// XXX: These definitions are duplicated in

Просмотреть файл

@ -29,7 +29,6 @@
#include "nsIFileTransportService.h"
#include "nsIURI.h"
#include "nsIStreamListener.h"
#include "nsCOMPtr.h"
#include "prprf.h"
#include "prmem.h" // for PR_Malloc
#include "prsystem.h" // for PR_GetSystemInfo
@ -38,8 +37,6 @@
#include "nsIFileChannel.h"
#include "nsInputStreamChannel.h"
#include "nsXPIDLString.h"
#include "nsISocketTransportService.h"
#include "nsIDNSService.h"
static NS_DEFINE_CID(kFileTransportService, NS_FILETRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
@ -62,6 +59,8 @@ nsIOService::nsIOService()
nsresult
nsIOService::Init()
{
nsresult rv;
// initialize the version and app components
mAppName = new nsCString("Netscape");
if (!mAppName) return NS_ERROR_OUT_OF_MEMORY;
@ -80,12 +79,31 @@ nsIOService::Init()
mAppPlatform = new nsCString(platformBuf);
if (!mAppPlatform) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
// We need to get references to these services so that we can shut them
// down later. If we wait until the nsIOService is being shut down,
// GetService will fail at that point.
rv = nsServiceManager::GetService(kSocketTransportServiceCID,
NS_GET_IID(nsISocketTransportService),
getter_AddRefs(mSocketTransportService));
if (NS_FAILED(rv)) return rv;
rv = nsServiceManager::GetService(kFileTransportService,
NS_GET_IID(nsIFileTransportService),
getter_AddRefs(mFileTransportService));
if (NS_FAILED(rv)) return rv;
rv = nsServiceManager::GetService(kDNSServiceCID,
NS_GET_IID(nsIDNSService),
getter_AddRefs(mDNSService));
return rv;
}
nsIOService::~nsIOService()
{
(void)SetOffline(PR_TRUE);
nsresult rv;
rv = SetOffline(PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv), "SetOffline failed");
// shut down the file transport service too:
rv = mFileTransportService->Shutdown();
NS_ASSERTION(NS_SUCCEEDED(rv), "file transport shutdown failed");
if (mAppName) delete mAppName;
if (mAppCodeName) delete mAppCodeName;
if (mAppVersion) delete mAppVersion;
@ -396,15 +414,8 @@ nsIOService::SetOffline(PRBool offline)
mOffline = offline;
if (offline) {
// be sure to try and shutdown both (even if the first fails)
nsresult rv, rv1 = NS_OK, rv2 = NS_OK;
NS_WITH_SERVICE(nsISocketTransportService, sts, kSocketTransportServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv1 = sts->Shutdown();
}
NS_WITH_SERVICE(nsIDNSService, dns, kDNSServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv2 = dns->Shutdown();
}
nsresult rv1 = mSocketTransportService->Shutdown();
nsresult rv2 = mDNSService->Shutdown();
if (NS_FAILED(rv1)) return rv1;
if (NS_FAILED(rv2)) return rv2;
}

Просмотреть файл

@ -25,6 +25,10 @@
#include "nsIIOService.h"
#include "nsString2.h"
#include "nsISocketTransportService.h"
#include "nsIFileTransportService.h"
#include "nsIDNSService.h"
#include "nsCOMPtr.h"
class nsIOService : public nsIIOService
{
@ -54,6 +58,9 @@ protected:
nsCString *mAppLanguage;
nsCString *mAppPlatform;
PRBool mOffline;
nsCOMPtr<nsISocketTransportService> mSocketTransportService;
nsCOMPtr<nsIFileTransportService> mFileTransportService;
nsCOMPtr<nsIDNSService> mDNSService;
};
#endif // nsIOService_h__

Просмотреть файл

@ -95,13 +95,6 @@ nsSocketTransportService::Create(nsISupports *aOuter, REFNSIID aIID, void **aRes
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
NS_WITH_SERVICE(nsIIOService, ios, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
PRBool offline;
rv = ios->GetOffline(&offline);
if (NS_FAILED(rv)) return rv;
if (offline) return NS_ERROR_FAILURE;
nsSocketTransportService* trans = new nsSocketTransportService();
if (trans == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
@ -556,6 +549,14 @@ nsSocketTransportService::CreateTransportOfType(const char* aSocketType,
nsIChannel** aResult)
{
nsresult rv = NS_OK;
NS_WITH_SERVICE(nsIIOService, ios, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
PRBool offline;
rv = ios->GetOffline(&offline);
if (NS_FAILED(rv)) return rv;
if (offline) return NS_ERROR_OFFLINE;
nsSocketTransport* transport = nsnull;
// Parameter validation...

Просмотреть файл

@ -27,10 +27,14 @@
#include "nsISupportsArray.h"
#include "nsError.h"
#include "prnetdb.h"
#include "nsString2.h"
#include "nsIIOService.h"
#include "nsIServiceManager.h"
#include "netCore.h"
#if defined(XP_PC)
#define WM_DNS_SHUTDOWN (WM_USER + 1)
#endif
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
@ -365,7 +369,6 @@ nsDNSEventProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
int error = nsnull;
nsDNSService * dnsService = (nsDNSService *)GetWindowLong(hWnd, GWL_USERDATA);
if ((dnsService != nsnull) && (uMsg == dnsService->mMsgFoundDNS)) {
// dns lookup complete - get error code
@ -391,11 +394,18 @@ nsDNSEventProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
delete lookup; // for now, until we implement a dns cache
break;
}
index--;
index--;
}
result = 0;
} else {
}
else if (uMsg == WM_DNS_SHUTDOWN) {
// dispose DNS EventHandler Window
(void) DestroyWindow(dnsService->mDNSWindow);
PostQuitMessage(0);
result = 0;
}
else {
result = DefWindowProc(hWnd, uMsg, wParam, lParam);
}
@ -408,10 +418,10 @@ nsDNSService::nsDNSService()
{
NS_INIT_REFCNT();
mThreadRunning = PR_FALSE;
mThread = nsnull;
#if defined(XP_MAC)
mThreadRunning = PR_FALSE;
mServiceRef = nsnull;
mCompletionQueue.qFlags = 0;
@ -490,18 +500,7 @@ nsDNSService::Init()
nsDNSService::~nsDNSService()
{
// deallocate cache
#if defined(XP_MAC)
// deallocate Open Transport Service Provider
OSStatus status = OTCloseProvider((ProviderRef)mServiceRef);
CloseOpenTransport(); // should be moved to terminate routine
#elif defined(XP_PC)
// dispose DNS EventHandler Window
(void) DestroyWindow(mDNSWindow);
#elif defined(XP_UNIX)
// XXXX - ?
#endif
Shutdown();
}
@ -516,13 +515,6 @@ nsDNSService::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
if (aOuter != nsnull)
return NS_ERROR_NO_AGGREGATION;
NS_WITH_SERVICE(nsIIOService, ios, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
PRBool offline;
rv = ios->GetOffline(&offline);
if (NS_FAILED(rv)) return rv;
if (offline) return NS_ERROR_FAILURE;
nsDNSService* dnsService = new nsDNSService();
if (dnsService == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
@ -562,11 +554,13 @@ nsDNSService::InitDNSThread(void)
mDNSWindow = CreateWindow(windowClass, "Mozilla:DNSWindow",
0, 0, 0, 10, 10, NULL, NULL, NULL, NULL);
(void) SetWindowLong(mDNSWindow, GWL_USERDATA, (long)this);
(void) SetWindowLong(mDNSWindow, GWL_USERDATA, (long)this);
// sync with Create thread
PRMonitor * monitor;
PRStatus status;
mThreadHandle = GetCurrentThread();
monitor = PR_CEnterMonitor(this);
mState = NS_OK;
@ -651,6 +645,14 @@ nsDNSService::Lookup(nsISupports* clientContext,
nsIRequest* *DNSRequest)
{
nsresult rv = NS_OK;
NS_WITH_SERVICE(nsIIOService, ios, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
PRBool offline;
rv = ios->GetOffline(&offline);
if (NS_FAILED(rv)) return rv;
if (offline) return NS_ERROR_OFFLINE;
PRStatus status = PR_SUCCESS;
nsHostEnt* hostentry = new nsHostEnt;
if (!hostentry) return NS_ERROR_OUT_OF_MEMORY;
@ -783,5 +785,32 @@ nsDNSService::Lookup(nsISupports* clientContext,
NS_IMETHODIMP
nsDNSService::Shutdown()
{
return NS_OK;
nsresult rv = NS_OK;
// XXX clean up outstanding requests
// XXX deallocate cache
#if defined(XP_MAC)
mThreadRunning = PR_FALSE;
// deallocate Open Transport Service Provider
OSStatus status = OTCloseProvider((ProviderRef)mServiceRef);
CloseOpenTransport(); // should be moved to terminate routine
PRThread* dnsServiceThread;
rv = mThread->GetPRThread(&dnsServiceThread);
if (dnsServiceThread)
PR_Mac_PostAsyncNotify(dnsServiceThread);
#elif defined(XP_PC)
SendMessage(mDNSWindow, WM_DNS_SHUTDOWN, 0, 0);
#elif defined(XP_UNIX)
// XXXX - ?
#endif
rv = mThread->Join();
return rv;
}

Просмотреть файл

@ -69,7 +69,6 @@ protected:
#endif
nsIThread * mThread;
PRBool mThreadRunning;
nsresult mState;
// nsDNSLookup cache? - list of nsDNSLookups, hash table (nsHashTable, nsStringKey)
@ -77,8 +76,9 @@ protected:
#if defined(XP_MAC)
PRBool mThreadRunning;
InetSvcRef mServiceRef;
QHdr mCompletionQueue;
QHdr mCompletionQueue;
#if TARGET_CARBON
OTClientContextPtr mClientContext;
@ -89,6 +89,7 @@ protected:
HWND mDNSWindow;
UINT mMsgFoundDNS;
nsVoidArray mCompletionQueue;
HANDLE mThreadHandle;
#elif defined(XP_UNIX)
//XXX - to be defined
#endif