hacks to get the transport socket to correctly run multiple urls over a connection. unfortunately, sockstub caches connections based on the url. so i'm faking it by keeping both the url struct used to open the connection around along with the url_struct for the current running url.

This commit is contained in:
mscott%netscape.com 1999-05-13 22:55:44 +00:00
Родитель e45c389e23
Коммит b3593daae0
2 изменённых файлов: 50 добавлений и 27 удалений

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

@ -119,8 +119,6 @@ NS_METHOD nsSocketTransport::Open(nsIURL *pURL)
// now the right protocol is set for the old networking world to use to complete the task // now the right protocol is set for the old networking world to use to complete the task
// so we can open it now.. // 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); rv = NS_OpenURL(pURL, m_inputStreamConsumer);
m_socketIsOpen = PR_TRUE; m_socketIsOpen = PR_TRUE;
@ -226,36 +224,33 @@ nsSocketTransport::OnDataAvailable(nsIURL* pURL,
if (m_socketIsOpen == PR_TRUE) // only do something useful if we are open... if (m_socketIsOpen == PR_TRUE) // only do something useful if we are open...
{ {
rv = GetURLInfo(pURL, &URL_s); rv = GetURLInfo(pURL, &URL_s); // this call is necessay 'cause it forces us to get m_bindedUrlStruct if we don't have it.
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv))
if (nsnull != URL_s) { {
if (nsnull != m_bindedUrlStruct)
/* Find the socket given URL_s pointer */ /* Find the socket given URL_s pointer */
m_ready_fd = NET_GetSocketToHashTable(URL_s); m_ready_fd = NET_GetSocketToHashTable(m_bindedUrlStruct);
} }
} else { else
return rv; return rv;
}
if (m_ready_fd == NULL) { if (m_ready_fd == NULL)
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
}
aIStream->GetLength(&len); aIStream->GetLength(&len);
memset(m_buffer, '\0', NET_SOCKSTUB_BUF_SIZE); memset(m_buffer, '\0', NET_SOCKSTUB_BUF_SIZE);
while (len > 0) { while (len > 0)
if (len < NET_SOCKSTUB_BUF_SIZE) { {
if (len < NET_SOCKSTUB_BUF_SIZE)
lenRead = len; lenRead = len;
} else
else {
lenRead = NET_SOCKSTUB_BUF_SIZE; lenRead = NET_SOCKSTUB_BUF_SIZE;
}
rv = aIStream->Read(m_buffer, lenRead, &lenRead); rv = aIStream->Read(m_buffer, lenRead, &lenRead);
if (NS_OK != rv) { if (NS_OK != rv)
return rv; return rv;
}
/* XXX: We should check if the write has succeeded or not */ /* XXX: We should check if the write has succeeded or not */
(int) NET_BlockingWrite(m_ready_fd, m_buffer, lenRead); (int) NET_BlockingWrite(m_ready_fd, m_buffer, lenRead);
@ -313,6 +308,7 @@ void nsSocketTransport::Initialize()
m_inputStream = NULL; m_inputStream = NULL;
m_inputStreamConsumer = NULL; m_inputStreamConsumer = NULL;
m_url = NULL; m_url = NULL;
m_bindedUrlStruct = NULL;
m_outStream = NULL; m_outStream = NULL;
m_outStreamSize = 0; m_outStreamSize = 0;
@ -344,26 +340,22 @@ nsSocketTransport::~nsSocketTransport()
rv = CloseCurrentConnection(); rv = CloseCurrentConnection();
NS_IF_RELEASE(mEventQService); NS_IF_RELEASE(mEventQService);
NS_IF_RELEASE(m_evQueue); NS_IF_RELEASE(m_evQueue);
NS_IF_RELEASE(m_outStream); NS_IF_RELEASE(m_outStream);
NS_IF_RELEASE(m_url); NS_IF_RELEASE(m_url);
NS_IF_RELEASE(m_inputStreamConsumer); NS_IF_RELEASE(m_inputStreamConsumer);
} }
NS_IMETHODIMP NS_IMETHODIMP nsSocketTransport::SetSocketBinding(nsIURL* pURL, URL_Struct_ ** aResult)
nsSocketTransport::GetURLInfo(nsIURL* pURL, URL_Struct_ **aResult)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsINetlibURL *pNetlibURL = NULL; nsINetlibURL *pNetlibURL = NULL;
if (pURL && aResult)
NS_PRECONDITION(aResult != nsnull, "invalid input argument");
if (aResult && pURL)
{ {
*aResult = nsnull;
if (pURL) if (pURL)
rv = pURL->QueryInterface(kINetlibURLIID, (void**)&pNetlibURL); rv = pURL->QueryInterface(kINetlibURLIID, (void**)&pNetlibURL);
if (NS_SUCCEEDED(rv) && pNetlibURL) { if (NS_SUCCEEDED(rv) && pNetlibURL)
{
pNetlibURL->GetURLInfo(aResult); pNetlibURL->GetURLInfo(aResult);
NS_RELEASE(pNetlibURL); NS_RELEASE(pNetlibURL);
} }
@ -372,6 +364,34 @@ nsSocketTransport::GetURLInfo(nsIURL* pURL, URL_Struct_ **aResult)
return rv; return rv;
} }
NS_IMETHODIMP
nsSocketTransport::GetURLInfo(nsIURL* pURL, URL_Struct_ **aResult)
{
// hack alert!!! we use a url struct to bind a socket transport to an active entry
// running the sockstub protocol. however the url struct is bound to the url. if you run
// another url through the socket, you'll get a different active entry back! (i.e.
// you won't get the original active entry that should be bound to the transport.
// so i'm going to remember the url_struct used to create the active entry and we'll
// always return that url struct for the lifetime ofthe transport. This will ensure,
// that we always get the original active entry and those allows us to run multiple
// urls through this connection.
SetSocketBinding(pURL, aResult);
if (!m_bindedUrlStruct && aResult)
m_bindedUrlStruct = *aResult;
else // we must be running a new url.....
{
// this is a god awful hack...i'm ashamed.....swap the url associated with
// the connection info out from under us with the new url...pURL.
nsIConnectionInfo * pConn = (nsIConnectionInfo *) m_bindedUrlStruct->fe_data;
if (pConn)
pConn->SetURL(pURL);
}
return NS_OK;
}
nsresult nsSocketTransport::CloseCurrentConnection() nsresult nsSocketTransport::CloseCurrentConnection()
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;

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

@ -78,6 +78,7 @@ public:
virtual ~nsSocketTransport(void); virtual ~nsSocketTransport(void);
NS_IMETHOD GetURLInfo(nsIURL* pURL, URL_Struct_ **aResult); NS_IMETHOD GetURLInfo(nsIURL* pURL, URL_Struct_ **aResult);
NS_IMETHOD SetSocketBinding(nsIURL* pURL, URL_Struct_ ** aResult);
// the following routines are called by the sock stub protocol hack.... // the following routines are called by the sock stub protocol hack....
// we should be able to remove this dependency once we move things to the new // we should be able to remove this dependency once we move things to the new
@ -118,6 +119,8 @@ protected:
nsIEventQueueService* mEventQService; nsIEventQueueService* mEventQService;
nsIEventQueue* m_evQueue; nsIEventQueue* m_evQueue;
char m_buffer[NET_SOCKSTUB_BUF_SIZE]; char m_buffer[NET_SOCKSTUB_BUF_SIZE];
URL_Struct_ * m_bindedUrlStruct;
}; };
#endif // nsSocketTransport_h__ #endif // nsSocketTransport_h__