Fixed for recent buffer changes.

This commit is contained in:
warren%netscape.com 1999-06-19 22:26:08 +00:00
Родитель b5c184f197
Коммит dbe7cd0107
6 изменённых файлов: 492 добавлений и 4 удалений

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

@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ___nsNetModRegEntry_h___
#define ___nsNetModRegEntry_h___
#include "nsINetModRegEntry.h"
class nsNetModRegEntry : nsINetModRegEntry {
public:
// nsISupports
NS_DECL_ISUPPORTS
// nsINetModRegEntry
NS_IMETHOD GetmNotify(nsINetNotify **aNotify);
NS_IMETHOD GetmEventQ(nsIEventQueue **aEventQ);
NS_IMETHOD GetmTopic(char **aTopic);
// nsNetModRegEntry
nsNetModRegEntry(char *aTopic, nsIEventQueue *aEventQ, nsINetNotify *aNotify);
~nsNetModRegEntry();
private:
char *mTopic;
nsIEventQueue *mEventQ;
nsINetNotify *mNotify;
};
#endif //___nsNetModRegEntry_h___

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

@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ___nsNetModuleMgr_h__
#define ___nsNetModuleMgr_h__
#include "nsINetModuleMgr.h"
//#include "prlock.h"
#include "nspr.h"
#include "nsISupportsArray.h"
class nsNetModuleMgr : public nsINetModuleMgr {
public:
// nsISupports
NS_DECL_ISUPPORTS
// nsINetModuleMgr
NS_IMETHOD RegisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID);
NS_IMETHOD UnregisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID);
NS_IMETHOD EnumerateModules(const char *aTopic, nsISimpleEnumerator **aEnumerator);
// nsNetModuleMgr
nsNetModuleMgr();
~nsNetModuleMgr();
nsISupportsArray *mEntries;
//PR_Lock *mLock;
};
#endif // ___nsNetModuleMgr_h__

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

@ -712,6 +712,7 @@ nsresult nsSocketTransport::doRead(PRInt16 aSelectFlags)
rv = NS_OK; rv = NS_OK;
} }
else if (NS_SUCCEEDED(rv)) { else if (NS_SUCCEEDED(rv)) {
// continue to return WOULD_BLOCK until we've completely finished this read
rv = NS_BASE_STREAM_WOULD_BLOCK; rv = NS_BASE_STREAM_WOULD_BLOCK;
} }
@ -978,7 +979,7 @@ nsSocketTransport::Resume(void)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// //
NS_IMETHODIMP NS_IMETHODIMP
nsSocketTransport::OnFull(void) nsSocketTransport::OnFull(nsIBuffer* buffer)
{ {
PR_LOG(gSocketLog, PR_LOG_DEBUG, PR_LOG(gSocketLog, PR_LOG_DEBUG,
("nsSocketTransport::OnFull() [this=%x].\n", this)); ("nsSocketTransport::OnFull() [this=%x].\n", this));
@ -998,7 +999,7 @@ nsSocketTransport::OnFull(void)
NS_IMETHODIMP NS_IMETHODIMP
nsSocketTransport::OnEmpty(void) nsSocketTransport::OnEmpty(nsIBuffer* buffer)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;

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

@ -93,8 +93,8 @@ public:
nsIStreamObserver *observer); nsIStreamObserver *observer);
// nsIBufferObserver methods: // nsIBufferObserver methods:
NS_IMETHOD OnFull(); NS_IMETHOD OnFull(nsIBuffer* buffer);
NS_IMETHOD OnEmpty(); NS_IMETHOD OnEmpty(nsIBuffer* buffer);
// nsSocketTransport methods: // nsSocketTransport methods:
nsSocketTransport(); nsSocketTransport();

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

@ -0,0 +1,316 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIBuffer.h"
//
// --------------------------------------------------------------------------
// Private implementation of a nsIBufferInputStream used by the
// nsSocketTransport implementation
// --------------------------------------------------------------------------
//
#if defined(XP_PC)
#include <windows.h> // Interlocked increment...
#endif
#include "nspr.h"
#include "nscore.h"
#include "nsSocketTransportStreams.h"
#include "nsSocketTransport.h"
#if defined(PR_LOGGING)
//
// Log module for SocketTransport logging...
//
// To enable logging (see prlog.h for full details):
//
// set NSPR_LOG_MODULES=nsSocketTransport:5
// set NSPR_LOG_FILE=nspr.log
//
// this enables PR_LOG_DEBUG level information and places all output in
// the file nspr.log
//
// gSocketLog is defined in nsSocketTransport.cpp
//
extern PRLogModuleInfo* gSocketLog;
#endif /* PR_LOGGING */
nsSocketTransportStream::nsSocketTransportStream()
{
NS_INIT_REFCNT();
mIsStreamBlocking = PR_FALSE;
mIsTransportSuspended = PR_FALSE;
mMonitor = nsnull;
mTransport = nsnull;
mBuffer = nsnull;
mStream = nsnull;
}
nsSocketTransportStream::~nsSocketTransportStream()
{
NS_IF_RELEASE(mTransport);
NS_IF_RELEASE(mStream);
NS_IF_RELEASE(mBuffer);
if (mMonitor) {
PR_DestroyMonitor(mMonitor);
mMonitor = nsnull;
}
}
nsresult nsSocketTransportStream::Init(nsSocketTransport* aTransport,
PRBool aBlockingFlag)
{
nsresult rv = NS_OK;
NS_ASSERTION(aTransport, "Null transport supplied.");
mIsStreamBlocking = aBlockingFlag;
mMonitor = PR_NewMonitor();
if (!mMonitor) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
if (NS_SUCCEEDED(rv) && aTransport) {
mTransport = aTransport;
NS_ADDREF(mTransport);
} else {
rv = NS_ERROR_NULL_POINTER;
}
if (NS_SUCCEEDED(rv)) {
rv = NS_NewBuffer(&mBuffer, MAX_IO_BUFFER_SIZE/2, 2*MAX_IO_BUFFER_SIZE, nsnull);
}
if (NS_SUCCEEDED(rv)) {
rv = NS_NewBufferInputStream(&mStream, mBuffer);
}
return rv;
}
nsresult nsSocketTransportStream::BlockTransport(void)
{
Lock();
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("nsSocketTransportStream::BlockTransport() [this=%x].\n", this));
//
// XXX: It would be nice to call mTransport->Suspend() here...
// Unfortunately, BlockTransport() is called within the transport lock.
// So, since NSPR locks are not re-enterent we must rely on the caller
// (ie. the transport) to suspend itself...
//
mIsTransportSuspended = PR_TRUE;
Unlock();
return NS_OK;
}
nsresult nsSocketTransportStream::FillStream(nsReadSegmentFun reader,
void* closure,
PRUint32 count,
PRUint32 *writeCount)
{
return mBuffer->WriteSegments(reader, closure, count, writeCount);
}
//
// --------------------------------------------------------------------------
// nsISupports implementation...
// --------------------------------------------------------------------------
//
NS_IMPL_THREADSAFE_ISUPPORTS(nsSocketTransportStream,
nsIBufferInputStream::GetIID());
//
// --------------------------------------------------------------------------
// nsIBaseStream implementation...
// --------------------------------------------------------------------------
//
NS_IMETHODIMP
nsSocketTransportStream::Close()
{
return mStream->Close();
}
//
// --------------------------------------------------------------------------
// nsIInputStream implementation...
// --------------------------------------------------------------------------
//
NS_IMETHODIMP
nsSocketTransportStream::GetLength(PRUint32 *aResult)
{
return mStream->GetLength(aResult);
}
NS_IMETHODIMP
nsSocketTransportStream::Read(char * aBuf, PRUint32 aCount,
PRUint32 *aReadCount)
{
nsresult rv;
// Enter the stream lock...
Lock();
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("+++ Entering nsSocketTransportStream::Read() [this=%x].\t"
"aCount=%d\n",
this, aCount));
do {
rv = mStream->Read(aBuf, aCount, aReadCount);
if (mIsStreamBlocking && (NS_BASE_STREAM_WOULD_BLOCK == rv)) {
Wait();
} else {
break;
}
} while (1);
//
// If the transport is blocked waiting for room in the input stream, then
// resume it...
//
if (mIsTransportSuspended && (*aReadCount) ) {
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("nsSocketTransportStream::Read() [this=%x]. "
"Resuming transport [%x].\n",
this, mTransport));
mTransport->Resume();
mIsTransportSuspended = PR_FALSE;
}
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("--- Leaving nsSocketTransportStream::Read() [this=%x].\t"
"rv = %x. aReadCount=%d\n",
this, rv, *aReadCount));
// Leave the stream lock...
Unlock();
return rv;
}
//
// --------------------------------------------------------------------------
// nsIBufferInputStream implementation...
// --------------------------------------------------------------------------
//
NS_IMETHODIMP
nsSocketTransportStream::GetBuffer(nsIBuffer* *result)
{
return mStream->GetBuffer(result);
}
NS_IMETHODIMP
nsSocketTransportStream::Search(const char *forString, PRBool ignoreCase, PRBool *found, PRUint32 *offsetSearchedTo)
{
return mStream->Search(forString, ignoreCase, found, offsetSearchedTo);
}
NS_IMETHODIMP
nsSocketTransportStream::FillFrom(nsIInputStream* aStream,
PRUint32 aCount,
PRUint32 *aWriteCount)
{
nsresult rv;
// Enter the stream lock...
Lock();
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("+++ Entering nsSocketTransportStream::Fill() [this=%x].\t"
"aCount=%d\n",
this, aCount));
rv = mStream->FillFrom(aStream, aCount, aWriteCount);
if (mIsStreamBlocking && (NS_BASE_STREAM_WOULD_BLOCK != rv)) {
Notify();
}
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("--- Leaving nsSocketTransportStream::Fill() [this=%x].\t"
"rv = %x. aWriteCount=%d\n",
this, rv, *aWriteCount));
// Leave the stream lock...
Unlock();
return rv;
}
NS_IMETHODIMP
nsSocketTransportStream::Fill(const char* aBuf,
PRUint32 aCount,
PRUint32 *aWriteCount)
{
nsresult rv;
// Enter the stream lock...
Lock();
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("+++ Entering nsSocketTransportStream::Fill() [this=%x].\t"
"aCount=%d\n",
this, aCount));
rv = mStream->Fill(aBuf, aCount, aWriteCount);
if (mIsStreamBlocking && (NS_BASE_STREAM_WOULD_BLOCK != rv)) {
Notify();
}
PR_LOG(gSocketLog, PR_LOG_DEBUG,
("--- Leaving nsSocketTransportStream::Fill() [this=%x].\t"
"rv = %x. aWriteCount=%d\n",
this, rv, *aWriteCount));
// Leave the stream lock...
Unlock();
return rv;
}

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

@ -0,0 +1,80 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsSocketTransportStreams_h___
#define nsSocketTransportStreams_h___
#include "prtypes.h"
#include "nsIBufferInputStream.h"
#include "nsIBuffer.h"
// Forward declarations...
class nsSocketTransport;
class nsSocketTransportStream : public nsIBufferInputStream
{
public:
nsSocketTransportStream();
// nsISupports methods:
NS_DECL_ISUPPORTS
// nsIBaseStream methods:
NS_IMETHOD Close();
// nsIInputStream methods:
NS_IMETHOD GetLength(PRUint32 *aResult);
NS_IMETHOD Read(char * aBuf, PRUint32 aCount, PRUint32 *aReadCount);
// nsIBufferInputStream methods:
NS_IMETHOD GetBuffer(nsIBuffer* *result);
NS_IMETHOD Search(const char *forString, PRBool ignoreCase, PRBool *found, PRUint32 *offsetSearchedTo);
NS_IMETHOD Fill(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
NS_IMETHOD FillFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval);
// nsSocketTransportStream methods:
nsresult Init(nsSocketTransport* aTransport, PRBool aBlockingFlag);
nsresult BlockTransport(void);
nsresult FillStream(nsReadSegmentFun reader, void* closure, PRUint32 count,
PRUint32 *writeCount);
void Lock(void) { NS_ASSERTION(mMonitor, "Monitor null."); PR_EnterMonitor(mMonitor); }
void Notify(void) { NS_ASSERTION(mMonitor, "Monitor null."); PR_Notify(mMonitor); }
void Wait(void) { NS_ASSERTION(mMonitor, "Monitor null."); PR_Wait(mMonitor, PR_INTERVAL_NO_TIMEOUT); }
void Unlock(void) { NS_ASSERTION(mMonitor, "Monitor null."); PR_ExitMonitor(mMonitor); }
protected:
virtual ~nsSocketTransportStream();
private:
PRBool mIsTransportSuspended;
PRBool mIsStreamBlocking;
PRMonitor* mMonitor;
nsIBuffer* mBuffer;
nsIBufferInputStream* mStream;
nsSocketTransport* mTransport;
};
#endif /* nsSocketTransportStreams_h___ */