From 9da8d671228baa83c822a99d785a1c3579fddfd1 Mon Sep 17 00:00:00 2001 From: "valeski%netscape.com" Date: Wed, 2 Jun 1999 17:23:45 +0000 Subject: [PATCH] nsIHTTPConnection.h - extended the nsIHTTPConnection interface so the internal streamlistener is accessible. nsHTTPConnection.cpp - GetInputStream now uses a syncStream listener. nsHTTPConnection.h - api update to support new nsIHTTPConnection interface and added nsIStreamListener member. nsHTTPResponseListener.cpp - added code to push data through the pipe --- .../protocol/http/public/nsIHTTPConnection.h | 4 +++ .../protocol/http/src/nsHTTPConnection.cpp | 31 +++++++++++++++++-- netwerk/protocol/http/src/nsHTTPConnection.h | 5 +++ .../http/src/nsHTTPResponseListener.cpp | 26 +++++++++------- 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/netwerk/protocol/http/public/nsIHTTPConnection.h b/netwerk/protocol/http/public/nsIHTTPConnection.h index 89b1d02f36e8..587ac2f73224 100644 --- a/netwerk/protocol/http/public/nsIHTTPConnection.h +++ b/netwerk/protocol/http/public/nsIHTTPConnection.h @@ -21,6 +21,8 @@ #include "nsIProtocolConnection.h" #include "nsHTTPEnums.h" +#include "nsIStreamListener.h" + class nsIHTTPEventSink; /* The nsIHTTPConnection class is the interface to an intance @@ -68,6 +70,8 @@ public: return NS_IHTTPConnection_IID; }; + NS_IMETHOD GetResponseDataListener(nsIStreamListener* *aListener) = 0; + }; //Possible errors diff --git a/netwerk/protocol/http/src/nsHTTPConnection.cpp b/netwerk/protocol/http/src/nsHTTPConnection.cpp index 89617b25c165..2af9391a535f 100644 --- a/netwerk/protocol/http/src/nsHTTPConnection.cpp +++ b/netwerk/protocol/http/src/nsHTTPConnection.cpp @@ -36,7 +36,8 @@ nsHTTPConnection::nsHTTPConnection( m_pHandler(dont_QueryInterface(i_Handler)), m_pEventSink(dont_QueryInterface(i_HTTPEventSink)), m_pResponse(nsnull), - m_pEventQ(dont_QueryInterface(i_EQ)) + m_pEventQ(dont_QueryInterface(i_EQ)), + m_pResponseDataListener(nsnull) { //TODO think if we need to make a copy of the URL and keep it here @@ -67,6 +68,8 @@ nsHTTPConnection::~nsHTTPConnection() delete m_pResponse; m_pResponse = 0; } + + NS_IF_RELEASE(m_pResponseDataListener); } NS_IMPL_ADDREF(nsHTTPConnection); @@ -92,12 +95,26 @@ nsHTTPConnection::Resume(void) NS_METHOD nsHTTPConnection::GetInputStream(nsIInputStream* *o_Stream) { +#if 0 + nsresult rv; + if (!m_bConnected) Open(); + + nsIInputStream* inStr; // this guy gets passed out to the user + rv = NS_NewSyncStreamListener(&m_pResponseDataListener, &inStr); + if (NS_FAILED(rv)) return rv; + + *o_Stream = inStr; + return NS_OK; + +#else + if (m_pResponse) return m_pResponse->GetInputStream(o_Stream); NS_ERROR("No response!"); return NS_OK; // change to error ? or block till response is set up? +#endif // if 0 } @@ -212,7 +229,7 @@ nsHTTPConnection::Open(void) #endif // jud rv = m_pHandler->GetTransport(host, unsignedPort, &temp); - if (temp) + if (NS_SUCCEEDED(rv) && temp) { m_pRequest->SetTransport(temp); @@ -291,3 +308,13 @@ nsHTTPConnection::GetURL(nsIURL* *o_URL) const return NS_OK; } +NS_IMETHODIMP +nsHTTPConnection::GetResponseDataListener(nsIStreamListener* *aListener) +{ + if (m_pResponseDataListener) { + *aListener = m_pResponseDataListener; + NS_ADDREF(m_pResponseDataListener); + } + return NS_OK; +} + diff --git a/netwerk/protocol/http/src/nsHTTPConnection.h b/netwerk/protocol/http/src/nsHTTPConnection.h index d775757bb0d8..d86d94e47a0b 100644 --- a/netwerk/protocol/http/src/nsHTTPConnection.h +++ b/netwerk/protocol/http/src/nsHTTPConnection.h @@ -99,6 +99,9 @@ public: NS_IMETHOD SetResponse(nsHTTPResponse* i_pResp) { if (i_pResp) m_pResponse = i_pResp; return NS_OK;}; + NS_IMETHOD GetResponseDataListener(nsIStreamListener* *aListener); + + private: nsCOMPtr m_pURL; PRBool m_bConnected; @@ -108,6 +111,8 @@ private: nsCOMPtr m_pEventSink; nsHTTPRequest* m_pRequest; nsHTTPResponse* m_pResponse; + + nsIStreamListener* m_pResponseDataListener; }; #endif /* _nsHTTPConnection_h_ */ diff --git a/netwerk/protocol/http/src/nsHTTPResponseListener.cpp b/netwerk/protocol/http/src/nsHTTPResponseListener.cpp index f2dda6011d29..041d9b631863 100644 --- a/netwerk/protocol/http/src/nsHTTPResponseListener.cpp +++ b/netwerk/protocol/http/src/nsHTTPResponseListener.cpp @@ -55,16 +55,7 @@ nsHTTPResponseListener::OnDataAvailable(nsISupports* context, PRUint32 i_SourceOffset, PRUint32 i_Length) { - // we should probably construct the stream only when we get the data... - // but for now... - nsIStreamListener* syncListener; - nsIInputStream* inStr; - - /* Jud... getting some unresolved stuff here... noticed that - nsSyncStreamListener isn't being exported!?! */ - //nsresult rv = NS_NewSyncStreamListener(&syncListener, &inStr); - //if (NS_FAILED(rv)) - // return rv; + nsIInputStream* inStr = nsnull; // Should I save this as a member variable? yes... todo nsIHTTPEventSink* pSink= nsnull; @@ -179,8 +170,21 @@ nsHTTPResponseListener::OnDataAvailable(nsISupports* context, if (bHeadersDone) { - // TODO push extrabuffer up the stream too.. How? JUD? + nsresult rv; + nsIStreamListener* internalListener = nsnull; + // Get our end of the pipe between us and the user's GetInputStream() + rv = m_pConnection->GetResponseDataListener(&internalListener); + if (NS_SUCCEEDED(rv)) { + // post the data to the stream listener + // XXX this is the wrong data and offsets I think. + rv = internalListener->OnDataAvailable(context, i_pStream, i_SourceOffset, i_Length); + NS_RELEASE(internalListener); + if (NS_FAILED(rv)) + return rv; + } + + // do whatever we want for the event sink return pSink->OnDataAvailable(context, inStr, i_SourceOffset, i_Length); }