+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
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
+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
--- /dev/null
+/*
+ * 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;
+ }
+ }
+}
+
--- /dev/null
+/*
+ * 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; }
+ }
+ }
+}
+
// 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
// 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;
void CompleteAsync ()
{
- lock (locker) {
- is_busy = false;
- }
+ is_busy = false;
}
// DownloadStringAsync
bool cancel = false;
try {
stream = request.EndGetRequestStream (result);
+ (stream as InternalWebRequestStreamWrapper).WebClient = this;
}
catch (WebException web) {
cancel = (web.Status == WebExceptionStatus.RequestCanceled);
}
}
+ 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)
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)
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;
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 ()
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