FtpWebRequest is always 2.0, remove unnecessary ifdefs
[mono.git] / mcs / class / System / System.Net / FtpDataStream.cs
index 9f448bf7538ef6bc871613cdb671f4e0aaf228c4..0638e28ca0b89c46c8658d5e8c9eb9de5bdfa8da 100644 (file)
@@ -12,6 +12,7 @@ using System.IO;
 using System.Net.Sockets;
 using System.Runtime.Remoting.Messaging;
 using System.Threading;
+using System.Net;
 
 #if NET_2_0
 
@@ -42,6 +43,10 @@ namespace System.Net
                        this.networkStream = new NetworkStream (socket, true);
                        this.isRead = isRead;
 
+                       if (request.EnableSsl) {
+                               FtpWebRequest.ChangeToSSLSocket (ref networkStream);
+                       }
+
                        closewh = new ManualResetEvent (false);
                }
 
@@ -87,7 +92,11 @@ namespace System.Net
 
                public override void Close ()
                {
-                       ((IDisposable) this).Dispose ();
+                       if (!disposed) {
+                               networkStream.Close ();
+                               request.SetTransferCompleted ();
+                               ((IDisposable) this).Dispose ();
+                       }
                }
 
                public override void Flush ()
@@ -108,19 +117,23 @@ namespace System.Net
                int ReadInternal (byte [] buffer, int offset, int size)
                {
                        int nbytes;
+
+                       request.CheckIfAborted ();
+
                        try {
                                // Probably it would be better to have the socket here
                                nbytes = networkStream.Read (buffer, offset, size);
-                       } catch (IOException exc) {
+                       } catch (IOException) {
                                throw new ProtocolViolationException ("Server commited a protocol violation");
                        }
 
                        totalRead += nbytes;
-                       if (nbytes == 0)
+                       if (nbytes == 0) {
                                contentLength = totalRead;
-                       if (totalRead >= contentLength)
+                               networkStream.Close ();
                                request.SetTransferCompleted ();
-                       
+                       }
+
                        return nbytes;
                }
 
@@ -159,6 +172,7 @@ namespace System.Net
 
                public override int Read (byte [] buffer, int offset, int size)
                {
+                       request.CheckIfAborted ();
                        IAsyncResult ar = BeginRead (buffer, offset, size, null, null);
                        if (!ar.IsCompleted && !ar.AsyncWaitHandle.WaitOne (request.ReadWriteTimeout, false))
                                throw new WebException ("Read timed out.", WebExceptionStatus.Timeout);
@@ -171,9 +185,11 @@ namespace System.Net
                
                void WriteInternal (byte [] buffer, int offset, int size)
                {
+                       request.CheckIfAborted ();
+                       
                        try {
                                networkStream.Write (buffer, offset, size);
-                       } catch (IOException exc) {
+                       } catch (IOException) {
                                throw new ProtocolViolationException ();
                        }
                }
@@ -212,6 +228,7 @@ namespace System.Net
 
                public override void Write (byte [] buffer, int offset, int size)
                {
+                       request.CheckIfAborted ();
                        IAsyncResult ar = BeginWrite (buffer, offset, size, null, null);
                        if (!ar.IsCompleted && !ar.AsyncWaitHandle.WaitOne (request.ReadWriteTimeout, false))
                                throw new WebException ("Read timed out.", WebExceptionStatus.Timeout);