Added code to make a file based socket transport. nsSocketTransport can now open a file or a network based socket.

When opening a url through a transport, convert the application url scheme to either file or 'sockstub' based on the type
of socket connection.


git-svn-id: svn://10.0.0.236/trunk@20342 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mscott%netscape.com 1999-02-11 02:56:58 +00:00
parent c0eabe2017
commit 45da5a7fd0
2 changed files with 78 additions and 21 deletions

View File

@ -87,17 +87,42 @@ NS_METHOD nsSocketTransport::Open(nsIURL *pURL)
NS_IF_ADDREF(pURL);
m_url = pURL;
pURL->SetHostPort(m_port);
const char * hostName = nsnull;
pURL->GetHost(&hostName);
if (hostName)
if (!m_isFileConnection)
{
PR_FREEIF(m_hostName);
m_hostName = PL_strdup(hostName);
pURL->SetHostPort(m_port);
const char * hostName = nsnull;
pURL->GetHost(&hostName);
if (hostName)
{
PR_FREEIF(m_hostName);
m_hostName = PL_strdup(hostName);
}
}
// mscott --> okay here's where the fact that the transport implementation is just a hack on
// the old world comes in....right now this transport class supports both socket and file based
// connections. The protocol is blind to this. They just gave us a url like: news://newshost.
// this particular url wants a network based socket so we need to use the sockstub hack. In order
// to do this, we need to change the protocol part of the url string to sockstub....
// if the url wants a file based socket connection, we change the protocol part of the url to
// file:// and piggy back off of the file protocol code. Why do we do this here? Well the rest of the
// app (both the app who runs the url and the protocol which is handling the url) can use protocol
// url parts like imap, mailbox, http, etc. Then when they are done with it and hand it to us for
// the underlying socket to be opened, we can turn around and tweek the protocol name to use the old
// world technology to build it (sockstub and file).
if (m_isFileConnection)
pURL->SetProtocol("file");
else // we want a network socket so use sockstub
pURL->SetProtocol("sockstub");
// now the right protocol is set for the old networking world to use to complete the task
// so we can open it now..
// running this url will cause a connection to be made on the socket.
rv = NS_OpenURL(pURL, m_inputStreamConsumer);
m_socketIsOpen = PR_TRUE;
}
@ -260,27 +285,51 @@ nsSocketTransport::nsSocketTransport(PRUint32 aPortToUse, const char * aHostName
else
m_hostName = PL_strdup("");
m_inputStream = NULL;
m_inputStreamConsumer = NULL;
m_url = NULL;
m_isFileConnection = PR_FALSE;
m_outStream = NULL;
m_outStreamSize = 0;
m_socketIsOpen = PR_FALSE; // initially, we have not opened the socket...
// common initialization code
Initialize();
}
/*
* Cache the EventQueueService...
*/
// XXX: What if this fails?
nsSocketTransport::nsSocketTransport(const char * fileName)
{
NS_INIT_REFCNT();
NS_PRECONDITION(fileName && *fileName, "Creating a socket with an invalid file name.");
if (fileName)
{
m_fileName = PL_strdup(fileName);
}
m_isFileConnection = PR_TRUE;
// common initialization code
Initialize();
}
void nsSocketTransport::Initialize()
{
m_inputStream = NULL;
m_inputStreamConsumer = NULL;
m_url = NULL;
m_outStream = NULL;
m_outStreamSize = 0;
m_socketIsOpen = PR_FALSE; // initially, we have not opened the socket...
/*
* Cache the EventQueueService...
*/
// XXX: What if this fails?
mEventQService = nsnull;
m_evQueue = nsnull;
nsresult rv = nsServiceManager::GetService(kEventQueueServiceCID,
mEventQService = nsnull;
m_evQueue = nsnull;
nsresult rv = nsServiceManager::GetService(kEventQueueServiceCID,
kIEventQueueServiceIID,
(nsISupports **)&mEventQService);
if (nsnull != mEventQService)
mEventQService->GetThreadEventQueue(PR_GetCurrentThread(), &m_evQueue);
if (nsnull != mEventQService)
mEventQService->GetThreadEventQueue(PR_GetCurrentThread(), &m_evQueue);
}
nsSocketTransport::~nsSocketTransport()

View File

@ -72,7 +72,10 @@ public:
////////////////////////////////////////////////////////////////////////////
// nsSocketTransport:
// we have two types of connections: socket and file based....
nsSocketTransport(PRUint32 aPortToUse, const char * aHostName);
nsSocketTransport(const char * fileName);
virtual ~nsSocketTransport(void);
NS_IMETHOD GetURLInfo(nsIURL* pURL, URL_Struct_ **aResult);
@ -81,16 +84,21 @@ public:
// net lib world...
PRUint32 GetPort() {return m_port;}
const char * GetHostName() { return m_hostName;}
const char * GetFileName() { return m_fileName;}
protected:
// use this function to close the underlying connection....
nsresult CloseCurrentConnection();
// common initialization code..
void Initialize();
// socket specific information...
PRUint32 m_port;
char *m_hostName;
char *m_fileName;
PRBool m_socketIsOpen; // set when we have opened a socket....
PRBool m_isFileConnection;
// the stream we write data from the socket into
nsIInputStream * m_inputStream;