2010-03-18 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Thu, 18 Mar 2010 11:59:29 +0000 (11:59 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Thu, 18 Mar 2010 11:59:29 +0000 (11:59 -0000)
* FtpWebResponse.cs:
* FtpWebRequest.cs: for non-data operations, make sure we send the
QUIT command upon completion when KeepAlive is false.
Fixes bug #589305.

svn path=/trunk/mcs/; revision=153825

mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/FtpWebRequest.cs
mcs/class/System/System.Net/FtpWebResponse.cs

index d87f8d59cc0ee56e186a74e46402cda2c868e4cd..9300632aefd452b233fb1b24b0ad910def5b86c9 100644 (file)
@@ -1,3 +1,10 @@
+2010-03-18 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * FtpWebResponse.cs:
+       * FtpWebRequest.cs: for non-data operations, make sure we send the
+       QUIT command upon completion when KeepAlive is false.
+       Fixes bug #589305.
+
 2010-03-16  Jb Evain  <jbevain@novell.com>
 
        * Dns.cs, HttpRequestCreator.cs, ServicePoint.cs: use MOONLIGHT
index 32ae9a1b26325eeea03e13a82c7daabb2fc933c6..bb765dd660c494f9c6f25fad8cfc33a129e2ae32 100644 (file)
@@ -204,13 +204,14 @@ namespace System.Net
                        }
                }
 
+               [MonoTODO ("We don't support KeepAlive = true")]
                public bool KeepAlive {
                        get {
                                return keepAlive;
                        }
                        set {
                                CheckRequestStarted ();
-                               keepAlive = value;
+                               //keepAlive = value;
                        }
                }
 
@@ -366,7 +367,7 @@ namespace System.Net
 
                                if (!InFinalState ()) {
                                        State = RequestState.Aborted;
-                                       ftpResponse = new FtpWebResponse (requestUri, method, FtpStatusCode.FileActionAborted, "Aborted by request");
+                                       ftpResponse = new FtpWebResponse (this, requestUri, method, FtpStatusCode.FileActionAborted, "Aborted by request");
                                }
                        }
                }
@@ -500,7 +501,7 @@ namespace System.Net
                void ProcessRequest () {
 
                        if (State == RequestState.Scheduled) {
-                               ftpResponse = new FtpWebResponse (requestUri, method, keepAlive);
+                               ftpResponse = new FtpWebResponse (this, requestUri, method, keepAlive);
 
                                try {
                                        ProcessMethod ();
@@ -642,7 +643,7 @@ namespace System.Net
                        
                        status = SendCommand (method, file_name);
 
-                       ftpResponse.Stream = new EmptyStream ();
+                       ftpResponse.Stream = Stream.Null;
                        
                        string desc = status.StatusDescription;
 
@@ -855,7 +856,7 @@ namespace System.Net
 
                Exception CreateExceptionFromResponse (FtpStatus status)
                {
-                       FtpWebResponse ftpResponse = new FtpWebResponse (requestUri, method, status);
+                       FtpWebResponse ftpResponse = new FtpWebResponse (this, requestUri, method, status);
                        
                        WebException exc = new WebException ("Server returned an error: " + status.StatusDescription, 
                                null, WebExceptionStatus.ProtocolError, ftpResponse);
@@ -875,6 +876,12 @@ namespace System.Net
                                CloseConnection ();
                }
 
+               internal void OperationCompleted ()
+               {
+                       if(!keepAlive)
+                               CloseConnection ();
+               }
+
                void SetCompleteWithError (Exception exc)
                {
                        if (asyncResult != null) {
@@ -1133,13 +1140,6 @@ namespace System.Net
                        if (InFinalState ())
                                throw new InvalidOperationException ("Cannot change final state");
                }
-
-               class EmptyStream : MemoryStream
-               {
-                       internal EmptyStream ()
-                               : base (new byte [0], false) {
-                       }
-               }
        }
 }
 
index fe715922bc3de636afa99893d1f0e6706dda0dac..e42156efcb053c482a3fa7e92b87a62958a4cfe9 100644 (file)
@@ -29,24 +29,28 @@ namespace System.Net
                string method;
                //bool keepAlive;
                bool disposed;
+               FtpWebRequest request;
                internal long contentLength = -1;
                
-               internal FtpWebResponse (Uri uri, string method, bool keepAlive)
+               internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, bool keepAlive)
                {
+                       this.request = request;
                        this.uri = uri;
                        this.method = method;
                        //this.keepAlive = keepAlive;
                }
 
-               internal FtpWebResponse (Uri uri, string method, FtpStatusCode statusCode, string statusDescription) {
+               internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, FtpStatusCode statusCode, string statusDescription)
+               {
+                       this.request = request;
                        this.uri = uri;
                        this.method = method;
                        this.statusCode = statusCode;
                        this.statusDescription = statusDescription;
                }
 
-               internal FtpWebResponse (Uri uri, string method, FtpStatus status) :
-                       this (uri, method, status.StatusCode, status.StatusDescription)
+               internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, FtpStatus status) :
+                       this (request, uri, method, status.StatusCode, status.StatusDescription)
                {
                }
                
@@ -128,8 +132,11 @@ namespace System.Net
                                return;
                        
                        disposed = true;
-                       if (stream != null)
+                       if (stream != null) {
                                stream.Close ();
+                               if (stream == Stream.Null)
+                                       request.OperationCompleted ();
+                       }
                        stream = null;
                }