+2007-01-24 Dick Porter <dick@ximian.com>
+
+ * NetworkStream.cs: 2.0 profile updates, based on a patch by
+ Sridhar Kulkarni (sridharkulkarni@gmail.com)
+
2007-01-23 Dick Porter <dick@ximian.com>
* TcpListener.cs:
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
+// Sridhar Kulkarni <sridharkulkarni@gmail.com>
//
// (C) 2002 Ximian, Inc. http://www.ximian.com
+// Copyright (C) 2002-2006 Novell, Inc. http://www.novell.com
//
//
using System.IO;
using System.Runtime.InteropServices;
+#if NET_2_0
+using System.Timers;
+using System.Threading;
+#endif
namespace System.Net.Sockets
{
}
}
+#if NET_2_0
+ public override bool CanTimeout
+ {
+ get {
+ return(true);
+ }
+ }
+#endif
+
public override bool CanWrite {
get {
return access == FileAccess.ReadWrite || access == FileAccess.Write;
}
}
+#if NET_2_0
+ public override int ReadTimeout
+ {
+ get {
+ return(socket.ReceiveTimeout);
+ }
+ set {
+ if (value <= 0 && value != Timeout.Infinite) {
+ throw new ArgumentOutOfRangeException ("value", "The value specified is less than or equal to zero and is not Infinite.");
+ }
+
+ socket.ReceiveTimeout = value;
+ }
+ }
+#endif
+
protected Socket Socket {
get {
return socket;
}
}
+#if NET_2_0
+ public override int WriteTimeout
+ {
+ get {
+ return(socket.SendTimeout);
+ }
+ set {
+ if (value <= 0 && value != Timeout.Infinite) {
+ throw new ArgumentOutOfRangeException ("value", "The value specified is less than or equal to zero and is not Infinite");
+ }
+
+ socket.SendTimeout = value;
+ }
+ }
+#endif
+
public override IAsyncResult BeginRead (byte [] buffer, int offset, int size,
AsyncCallback callback, object state)
{
((IDisposable) this).Dispose ();
}
+#if NET_2_0
+ public void Close (int timeout)
+ {
+ if (timeout < -1) {
+ throw new ArgumentOutOfRangeException ("timeout", "timeout is less than -1");
+ }
+
+ System.Timers.Timer close_timer = new System.Timers.Timer ();
+ close_timer.Elapsed += new ElapsedEventHandler (OnTimeoutClose);
+ /* NB timeout is in milliseconds here, cf
+ * seconds in Socket.Close(int)
+ */
+ close_timer.Interval = timeout;
+ close_timer.AutoReset = false;
+ close_timer.Enabled = true;
+ }
+
+ private void OnTimeoutClose (object source, ElapsedEventArgs e)
+ {
+ this.Close ();
+ }
+#endif
+
protected
#if NET_2_0
override
System.Net.Configuration/ConnectionManagementSectionTest.cs
System.Net.Configuration/HttpWebRequestElementTest.cs
System.Net.Configuration/WebRequestModulesSectionTest.cs
+System.Net.Sockets/NetworkStreamTest.cs
System.Net.Sockets/TcpClientTest.cs
System.Net.Sockets/TcpListenerTest.cs
System.Net.Sockets/SocketTest.cs
+2007-01-24 Dick Porter <dick@ximian.com>
+
+ * NetworkStreamTest.cs: Test 2.0 ReadTimeout property
+
2007-01-23 Dick Porter <dick@ximian.com>
* TcpListenerTest.cs: Test 2.0 Start(int) overload
--- /dev/null
+// System.Net.Sockets.NetworkStreamTest.cs
+//
+// Author:
+// Dick Porter (dick@ximian.com)
+//
+// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
+//
+
+using System.Net.Sockets;
+using System.Net;
+using System;
+using System.IO;
+using NUnit.Framework;
+
+
+namespace MonoTests.System.Net.Sockets
+{
+ [TestFixture]
+ public class NetworkStreamTest
+ {
+#if NET_2_0
+ [Test]
+ public void ReadTimeout ()
+ {
+ Socket sock = new Socket (AddressFamily.InterNetwork,
+ SocketType.Stream,
+ ProtocolType.Tcp);
+ Socket listen = new Socket (AddressFamily.InterNetwork,
+ SocketType.Stream,
+ ProtocolType.Tcp);
+ IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 0);
+
+ listen.Bind (ep);
+ listen.Listen (1);
+
+ sock.Connect (listen.LocalEndPoint);
+
+ NetworkStream stream = new NetworkStream (sock);
+ stream.ReadTimeout = 1000;
+
+ byte[] buf = new byte[1024];
+
+ try {
+ stream.Read (buf, 0, buf.Length);
+ Assert.Fail ("ReadTimeout #1");
+ } catch (IOException ex) {
+ Exception inner = ex.InnerException;
+ SocketException sockex = inner as SocketException;
+
+ Assert.IsNotNull (sockex, "ReadTimeout #2");
+
+/* Linux gives error 10035 (EWOULDBLOCK) here, whereas windows has 10060 (ETIMEDOUT)
+ Assertion.AssertEquals ("ReadTimeout #3",
+ 10060,
+ sockex.ErrorCode);
+*/
+ } catch {
+ Assert.Fail ("ReadTimeout #4");
+ } finally {
+ stream.Close ();
+ sock.Close ();
+ listen.Close ();
+ }
+ }
+#endif
+ }
+}