From ec7d6b07da9a4a04535f4b25d9e00011077370cb Mon Sep 17 00:00:00 2001 From: "valeski%netscape.com" Date: Thu, 6 Jan 2000 00:29:48 +0000 Subject: [PATCH] 23039. r=rpotts. FTP wasn't closing the data connection after data transfer. This was causing it to hang, waiting for the command channel to unblock. --- netwerk/base/public/Makefile.in | 1 + netwerk/base/public/makefile.win | 1 + netwerk/base/public/nsISocketTransport.idl | 29 ++++++++++++++ netwerk/base/src/nsSocketTransport.cpp | 38 +++++++++---------- netwerk/base/src/nsSocketTransport.h | 6 ++- .../ftp/src/nsFtpConnectionThread.cpp | 6 +++ 6 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 netwerk/base/public/nsISocketTransport.idl diff --git a/netwerk/base/public/Makefile.in b/netwerk/base/public/Makefile.in index 1b1faa20a2a9..b443e5cac72a 100644 --- a/netwerk/base/public/Makefile.in +++ b/netwerk/base/public/Makefile.in @@ -50,6 +50,7 @@ XPIDLSRCS = \ nsIFileSystem.idl \ nsIUnicharStreamLoader.idl \ nsINetPrompt.idl \ + nsISocketTransport.idl \ $(NULL) EXPORTS = \ diff --git a/netwerk/base/public/makefile.win b/netwerk/base/public/makefile.win index f91bed87dedc..bc8505c0aebb 100644 --- a/netwerk/base/public/makefile.win +++ b/netwerk/base/public/makefile.win @@ -51,6 +51,7 @@ XPIDLSRCS = \ .\nsIFileSystem.idl \ .\nsIUnicharStreamLoader.idl \ .\nsINetPrompt.idl \ + .\nsISocketTransport.idl \ $(NULL) include <$(DEPTH)/config/rules.mak> diff --git a/netwerk/base/public/nsISocketTransport.idl b/netwerk/base/public/nsISocketTransport.idl new file mode 100644 index 000000000000..d0de9e41db5a --- /dev/null +++ b/netwerk/base/public/nsISocketTransport.idl @@ -0,0 +1,29 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +[scriptable, uuid(785CA0F0-C39E-11d3-9ED6-0010A4053FD0)] +interface nsISocketTransport : nsISupports +{ + attribute boolean reuseConnection; +}; diff --git a/netwerk/base/src/nsSocketTransport.cpp b/netwerk/base/src/nsSocketTransport.cpp index 3cc75d886775..10987d7e7727 100644 --- a/netwerk/base/src/nsSocketTransport.cpp +++ b/netwerk/base/src/nsSocketTransport.cpp @@ -1189,33 +1189,29 @@ void nsSocketTransport::SetSocketTimeout(PRIntervalTime aTimeInterval) NS_IMPL_THREADSAFE_ADDREF(nsSocketTransport); NS_IMPL_THREADSAFE_RELEASE(nsSocketTransport); +NS_IMPL_QUERY_INTERFACE5(nsSocketTransport, + nsIRequest, nsIChannel, + nsIDNSListener, nsIPipeObserver, + nsISocketTransport); +// +// -------------------------------------------------------------------------- +// nsISocketTransport implementation... +// -------------------------------------------------------------------------- +// NS_IMETHODIMP -nsSocketTransport::QueryInterface(const nsIID& aIID, void* *aInstancePtr) +nsSocketTransport::GetReuseConnection(PRBool *_retval) { - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsIChannel)) || - aIID.Equals(NS_GET_IID(nsIRequest)) || - aIID.Equals(NS_GET_IID(nsISupports))) { - *aInstancePtr = NS_STATIC_CAST(nsIChannel*, this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDNSListener))) { - *aInstancePtr = NS_STATIC_CAST(nsIDNSListener*, this); - NS_ADDREF_THIS(); + *_retval = !mCloseConnectionOnceDone; return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIPipeObserver))) { - *aInstancePtr = NS_STATIC_CAST(nsIPipeObserver*, this); - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; } +NS_IMETHODIMP +nsSocketTransport::SetReuseConnection(PRBool aReuse) +{ + mCloseConnectionOnceDone = !aReuse; + return NS_OK; +} // diff --git a/netwerk/base/src/nsSocketTransport.h b/netwerk/base/src/nsSocketTransport.h index 9d6c155ee073..4caf2cc91671 100644 --- a/netwerk/base/src/nsSocketTransport.h +++ b/netwerk/base/src/nsSocketTransport.h @@ -27,8 +27,8 @@ #include "prio.h" #include "prnetdb.h" #include "prinrval.h" - #include "nsCOMPtr.h" +#include "nsISocketTransport.h" #include "nsIChannel.h" #include "nsIInputStream.h" #include "nsIBufferInputStream.h" @@ -110,12 +110,14 @@ enum nsSocketReadWriteInfo { class nsSocketTransportService; class nsIInterfaceRequestor; -class nsSocketTransport : public nsIChannel, +class nsSocketTransport : public nsISocketTransport, + public nsIChannel, public nsIDNSListener, public nsIPipeObserver { public: NS_DECL_ISUPPORTS + NS_DECL_NSISOCKETTRANSPORT NS_DECL_NSIREQUEST NS_DECL_NSICHANNEL NS_DECL_NSIPIPEOBSERVER diff --git a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp index 3c3088b272c9..441748c88370 100644 --- a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp +++ b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp @@ -23,6 +23,7 @@ #include "nsFtpConnectionThread.h" #include "nsIEventQueueService.h" #include "nsIStringStream.h" +#include "nsISocketTransport.h" #include "nsIPipe.h" #include "nsIMIMEService.h" #include "nsIStreamConverterService.h" @@ -1526,6 +1527,11 @@ nsFtpConnectionThread::R_pasv() { getter_AddRefs(mDPipe)); // the data channel if (NS_FAILED(rv)) return FTP_ERROR; + nsCOMPtr sTrans = do_QueryInterface(mDPipe, &rv); + if (NS_FAILED(rv)) return FTP_ERROR; + + if (NS_FAILED(sTrans->SetReuseConnection(PR_FALSE))) return FTP_ERROR; + // The FTP connection thread will receive transport leve // AsyncOpen notifications. rv = mDPipe->AsyncOpen(this, nsnull);