In .:
authorSebastien Pouliot <sebastien@ximian.com>
Mon, 11 Jan 2010 20:26:27 +0000 (20:26 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Mon, 11 Jan 2010 20:26:27 +0000 (20:26 -0000)
2010-01-11  Sebastien Pouliot  <sebastien@ximian.com>

* System.Net.dll.sources: Add InternalWebRequestStreamWrapper.cs
* Makefile: Add reference to System.Core (for Action<T>)

In System.Net:
2010-01-11  Sebastien Pouliot  <sebastien@ximian.com>

* InternalWebRequestStreamWrapper.cs: New. Moved (and adapted)
from Moonlight System.Windows.Browser assembly.
* InternalWebResponseStreamWrapper.cs: New. Moved (and adapted)
from Moonlight System.Windows.Browser assembly.
* WebClient_2_1.cs: Remove custom delegate declaration (Gendarme's
AvoidDeclaringCustomDelegatesRule). Remove locking over a variable
(Gendarme's ReviewLockUsedOnlyForOperationsOnVariablesRule).
Avoid potential race with event handlers (Gendarme's
ProtectCallsToEventDelegatesRule). Implement OnWriteStreamClosed
* WebRequest_2_1.cs: Signature change from delegate to
Action<long,long,object>. Found using Gendarme's
AvoidDeclaringCustomDelegatesRule

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

mcs/class/System.Net/ChangeLog
mcs/class/System.Net/Makefile
mcs/class/System.Net/System.Net/ChangeLog
mcs/class/System.Net/System.Net/InternalWebRequestStreamWrapper.cs [new file with mode: 0644]
mcs/class/System.Net/System.Net/InternalWebResponseStreamWrapper.cs [new file with mode: 0644]
mcs/class/System.Net/System.Net/WebClient_2_1.cs
mcs/class/System.Net/System.Net/WebRequest_2_1.cs
mcs/class/System.Net/net_2_1_raw_System.Net.dll.sources

index 51555aa08a0a06826d2c9197fd7eb1eb730df49b..f456a3827878ccb84b020837201a2f999ac4fb85 100644 (file)
@@ -1,3 +1,8 @@
+2010-01-11  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * System.Net.dll.sources: Add InternalWebRequestStreamWrapper.cs
+       * Makefile: Add reference to System.Core (for Action<T>)
+
 2009-12-04  Sebastien Pouliot  <sebastien@ximian.com>
 
        * System.Net.dll.sources: Remove (almost) everything. This 
index 89a625fba8ed4de19c9707160d134cdb7187d94a..9beaba3a6d0114c88dd09c0f396ae4cc7bf959e7 100644 (file)
@@ -3,7 +3,7 @@ SUBDIRS =
 include ../../build/rules.make
 
 LIBRARY = System.Net.dll
-LIB_MCS_FLAGS =  -unsafe -r:System.dll -d:NET_2_1 -d:NET_2_0 -d:NET_1_1
+LIB_MCS_FLAGS =  -unsafe -r:System.dll -r:System.Core.dll -d:NET_2_1 -d:NET_2_0 -d:NET_1_1
 
 ifneq (2.1, $(FRAMEWORK_VERSION))
 LIB_MCS_FLAGS += -d:NET_3_5 -nowarn:1720
index dc83e55703200b5eb51c2be0da618972227c8197..e86fd430353e0ddf4e3028e0642949b0e5a26d79 100644 (file)
@@ -1,3 +1,18 @@
+2010-01-11  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * InternalWebRequestStreamWrapper.cs: New. Moved (and adapted) 
+       from Moonlight System.Windows.Browser assembly.
+       * InternalWebResponseStreamWrapper.cs: New. Moved (and adapted) 
+       from Moonlight System.Windows.Browser assembly.
+       * WebClient_2_1.cs: Remove custom delegate declaration (Gendarme's
+       AvoidDeclaringCustomDelegatesRule). Remove locking over a variable
+       (Gendarme's ReviewLockUsedOnlyForOperationsOnVariablesRule). 
+       Avoid potential race with event handlers (Gendarme's 
+       ProtectCallsToEventDelegatesRule). Implement OnWriteStreamClosed
+       * WebRequest_2_1.cs: Signature change from delegate to 
+       Action<long,long,object>. Found using Gendarme's
+       AvoidDeclaringCustomDelegatesRule
+
 2009-12-12  Rolf Bjarne Kvinge  <RKvinge@novell.com>
 
        * WebClient_2_1.cs: When creating the request we need to copy over
diff --git a/mcs/class/System.Net/System.Net/InternalWebRequestStreamWrapper.cs b/mcs/class/System.Net/System.Net/InternalWebRequestStreamWrapper.cs
new file mode 100644 (file)
index 0000000..cb86632
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * InternalWebRequestStreamWrapper.cs.
+ *
+ * Contact:
+ *   Moonlight List (moonlight-list@lists.ximian.com)
+ *
+ * Copyright 2008,2010 Novell, Inc. (http://www.novell.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ * 
+ */
+
+using System.IO;
+
+namespace System.Net {
+
+       internal sealed class InternalWebRequestStreamWrapper : Stream {
+
+               Stream stream;
+               
+               internal InternalWebRequestStreamWrapper (Stream s)
+               {
+                       stream = s;
+               }
+
+               public override bool CanRead {
+                       get {
+                                return stream.CanRead;
+                       }
+               }
+
+               public override bool CanSeek {
+                       get {
+                                return stream.CanSeek;
+                       }
+               }
+
+               public override bool CanWrite {
+                       get {
+                                return stream.CanWrite;
+                       }
+               }
+
+               public override long Length {
+                       get {
+                                return stream.Length;
+                       }
+               }
+
+               public override long Position {
+                       get {
+                                return stream.Position;
+                       }
+                       set {
+                               stream.Position = value;
+                       }
+               }
+
+               public override void Flush ()
+               {
+                       stream.Flush ();
+               }
+
+               public override void Close ()
+               {
+                       try {
+                               stream.Close ();
+                       }
+                       finally {
+                               // if used from WebClient then notify that the stream was closed
+                               if (WebClient != null)
+                                       WebClient.WriteStreamClosedCallback ();
+                       }
+               }
+
+               public override void SetLength (long value)
+               {
+                       stream.SetLength (value);
+               }
+
+               public override int Read (byte [] buffer, int offset, int count)
+               {
+                       return stream.Read (buffer, offset, count);
+               }
+
+               public override void Write (byte [] buffer, int offset, int count)
+               {
+                       // make sure we start with a new line
+                       if ((count > 0) && (Length == 0))
+                               stream.WriteByte ((byte) '\n');
+
+                       stream.Write (buffer, offset, count);
+               }
+
+               public override void WriteByte (byte value)
+               {
+                       stream.WriteByte (value);
+               }
+
+               public override long Seek (long offset, SeekOrigin origin)
+               {
+                       return stream.Seek (offset, origin);
+               }
+
+               internal Stream InnerStream {
+                       get { return stream; }
+               }
+
+               internal WebClient WebClient {
+                       get; set;
+               }
+       }
+}
+
diff --git a/mcs/class/System.Net/System.Net/InternalWebResponseStreamWrapper.cs b/mcs/class/System.Net/System.Net/InternalWebResponseStreamWrapper.cs
new file mode 100644 (file)
index 0000000..00d44fa
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * InternalWebResponseStreamWrapper.cs.
+ *
+ * Contact:
+ *   Moonlight List (moonlight-list@lists.ximian.com)
+ *
+ * Copyright 2008,2010 Novell, Inc. (http://www.novell.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ * 
+ */
+
+using System.IO;
+
+namespace System.Net {
+
+       // simply a read-only wrapper around a stream + a no-op Close
+       internal sealed class InternalWebResponseStreamWrapper : Stream {
+
+               private Stream stream;
+               
+               internal InternalWebResponseStreamWrapper (Stream s)
+               {
+                       stream = s;
+               }
+
+               public override bool CanRead {
+                       get {
+                                return stream.CanRead;
+                       }
+               }
+
+               public override bool CanSeek {
+                       get {
+                                return stream.CanSeek;
+                       }
+               }
+
+               public override bool CanWrite {
+                       get {
+                                return false;
+                       }
+               }
+
+               public override long Length {
+                       get {
+                                return stream.Length;
+                       }
+               }
+
+               public override long Position {
+                       get {
+                                return stream.Position;
+                       }
+                       set {
+                               stream.Position = value;
+                       }
+               }
+
+               public override void Flush ()
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override void Close ()
+               {
+                       // We cannot call "stream.Close" on a memory stream since it deletes the data
+               }
+
+               public override void SetLength (long value)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override int Read (byte [] buffer, int offset, int count)
+               {
+                       return stream.Read (buffer, offset, count);
+               }
+
+               public override void Write (byte [] buffer, int offset, int count)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override void WriteByte (byte value)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override long Seek (long offset, SeekOrigin origin)
+               {
+                       return stream.Seek (offset, origin);
+               }
+
+               internal Stream InnerStream {
+                       get { return stream; }
+               }
+       }
+}
+
index 8a474ce168b44592ae2d939e29a33ac6b171ff0c..a099979f3bc896726d0d0d1acdb33e230336d23a 100644 (file)
@@ -9,7 +9,7 @@
 //     Stephane Delcroix (sdelcroix@novell.com)
 //
 // Copyright 2003 Ximian, Inc. (http://www.ximian.com)
-// Copyright 2006, 2008, 2009 Novell, Inc. (http://www.novell.com)
+// Copyright 2006, 2008, 2009-2010 Novell, Inc. (http://www.novell.com)
 //
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -40,8 +40,6 @@ namespace System.Net {
        // note: this type is effectively sealed to transparent code since it's default .ctor is marked with [SecuritySafeCritical]
        public class WebClient {
 
-               private delegate void ProgressChangedDelegate (long read, long length, object state);
-
                WebHeaderCollection headers;
                WebHeaderCollection responseHeaders;
                string baseAddress;
@@ -190,9 +188,7 @@ namespace System.Net {
 
                void CompleteAsync ()
                {
-                       lock (locker) {
-                               is_busy = false;
-                       }
+                       is_busy = false;
                }
 
                //    DownloadStringAsync
@@ -336,6 +332,7 @@ namespace System.Net {
                        bool cancel = false;
                        try {
                                stream = request.EndGetRequestStream (result);
+                               (stream as InternalWebRequestStreamWrapper).WebClient = this;
                        }
                        catch (WebException web) {
                                cancel = (web.Status == WebExceptionStatus.RequestCanceled);
@@ -350,6 +347,27 @@ namespace System.Net {
                        }
                }
 
+               internal void WriteStreamClosedCallback ()
+               {
+                       try {
+                               request.BeginGetResponse (OpenWriteAsyncResponseCallback, null);
+                       }
+                       catch (Exception e) {
+                               OnWriteStreamClosed (new WriteStreamClosedEventArgs (e));
+                       }
+               }
+
+               private void OpenWriteAsyncResponseCallback (IAsyncResult result)
+               {
+                       try {
+                               WebResponse response = request.EndGetResponse (result);
+                               ProcessResponse (response);
+                       }
+                       catch (Exception e) {
+                               OnWriteStreamClosed (new WriteStreamClosedEventArgs (e));
+                       }
+               }
+
                //    UploadStringAsync
 
                public void UploadStringAsync (Uri address, string data)
@@ -432,50 +450,56 @@ namespace System.Net {
 
                protected virtual void OnDownloadProgressChanged (DownloadProgressChangedEventArgs e)
                {
-                       if (DownloadProgressChanged != null) {
-                               DownloadProgressChanged (this, e);
-                       }
+                       DownloadProgressChangedEventHandler handler = DownloadProgressChanged;
+                       if (handler != null)
+                               handler (this, e);
                }
                
                protected virtual void OnOpenReadCompleted (OpenReadCompletedEventArgs args)
                {
                        CompleteAsync ();
-                       if (OpenReadCompleted != null) {
-                               OpenReadCompleted (this, args);
-                       }
+                       OpenReadCompletedEventHandler handler = OpenReadCompleted;
+                       if (handler != null)
+                               handler (this, args);
                }
 
                protected virtual void OnDownloadStringCompleted (DownloadStringCompletedEventArgs args)
                {
                        CompleteAsync ();
-                       if (DownloadStringCompleted != null) {
-                               DownloadStringCompleted (this, args);
-                       }
+                       DownloadStringCompletedEventHandler handler = DownloadStringCompleted;
+                       if (handler != null)
+                               handler (this, args);
                }
 
                protected virtual void OnOpenWriteCompleted (OpenWriteCompletedEventArgs args)
                {
                        CompleteAsync ();
-                       if (OpenWriteCompleted != null)
-                               OpenWriteCompleted (this, args);
+                       OpenWriteCompletedEventHandler handler = OpenWriteCompleted;
+                       if (handler != null)
+                               handler (this, args);
                }
 
                protected virtual void OnUploadProgressChanged (UploadProgressChangedEventArgs e)
                {
-                       if (UploadProgressChanged != null)
-                               UploadProgressChanged (this, e);
+                       UploadProgressChangedEventHandler handler = UploadProgressChanged;
+                       if (handler != null)
+                               handler (this, e);
                }
 
                protected virtual void OnUploadStringCompleted (UploadStringCompletedEventArgs args)
                {
                        CompleteAsync ();
-                       if (UploadStringCompleted != null)
-                               UploadStringCompleted (this, args);
+                       UploadStringCompletedEventHandler handler = UploadStringCompleted;
+                       if (handler != null)
+                               handler (this, args);
                }
 
                protected virtual void OnWriteStreamClosed (WriteStreamClosedEventArgs e)
                {
-                       throw new NotImplementedException ();
+                       CompleteAsync ();
+                       WriteStreamClosedEventHandler handler = WriteStreamClosed;
+                       if (handler != null)
+                               handler (this, e);
                }
 
                protected virtual WebRequest GetWebRequest (Uri address)
@@ -488,7 +512,7 @@ namespace System.Net {
 
                        WebRequest request = WebRequest.Create (uri);
 
-                       request.SetupProgressDelegate ((ProgressChangedDelegate) delegate (long read, long length, object state) {
+                       request.SetupProgressDelegate (delegate (long read, long length, object state) {
                                OnDownloadProgressChanged (new DownloadProgressChangedEventArgs (read, length, state));
                        });
                        return request;
index c06cf6da17a7b55fc7539513b4572936ae551e04..a8923bfcd3714fee5e52e587cda6e7df1d49dc20 100644 (file)
@@ -135,11 +135,11 @@ namespace System.Net {
                        return true;
                }
 
-               internal void SetupProgressDelegate (Delegate progress_delegate)
+               internal void SetupProgressDelegate (Action<long,long,object> progress)
                {
-                       FieldInfo fi = GetType ().GetField ("progress_delegate", BindingFlags.Instance | BindingFlags.NonPublic);
+                       FieldInfo fi = GetType ().GetField ("progress", BindingFlags.Instance | BindingFlags.NonPublic);
                        if (fi != null)
-                               fi.SetValue (this, progress_delegate);
+                               fi.SetValue (this, progress);
                }
 
                static Exception NotImplemented ()
index a3b93fbdef4e7c44d9b17993b5125f64801c0227..bf3a53c33e9dc753bfa1334f75be6b94ca397f07 100644 (file)
@@ -2,6 +2,8 @@ Assembly/AssemblyInfo.cs
 System.Net/Dns_2_1.cs
 System.Net/HttpWebRequest_2_1.cs
 System.Net/HttpWebResponse_2_1.cs
+System.Net/InternalWebRequestStreamWrapper.cs
+System.Net/InternalWebResponseStreamWrapper.cs
 System.Net/WebExceptionStatus_2_1.cs
 System.Net/WebHeaderCollection_2_1.cs
 System.Net/WebClient_2_1.cs