1 // System.Net.Sockets.NetworkStreamTest.cs
4 // Dick Porter (dick@ximian.com)
6 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
9 using System.Net.Sockets;
13 using NUnit.Framework;
16 namespace MonoTests.System.Net.Sockets
19 public class NetworkStreamTest
24 [ExpectedException(typeof(IOException))]
25 public void NetworkStreamConnection ()
27 IPEndPoint ipe = new IPEndPoint(Dns.GetHostEntry ("www.google.com").AddressList [0], 80);
28 Socket s = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
30 NetworkStream ns = new NetworkStream (s);
34 public void ReadTimeout ()
36 Socket sock = new Socket (AddressFamily.InterNetwork,
39 Socket listen = new Socket (AddressFamily.InterNetwork,
42 IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 0);
47 sock.Connect (listen.LocalEndPoint);
49 NetworkStream stream = new NetworkStream (sock);
50 stream.ReadTimeout = 1000;
52 byte[] buf = new byte[1024];
55 stream.Read (buf, 0, buf.Length);
56 Assert.Fail ("ReadTimeout #1");
57 } catch (IOException ex) {
58 Exception inner = ex.InnerException;
59 SocketException sockex = inner as SocketException;
61 Assert.IsNotNull (sockex, "ReadTimeout #2");
63 /* Linux gives error 10035 (EWOULDBLOCK) here, whereas windows has 10060 (ETIMEDOUT)
64 Assert.AreEqual (10060, sockex.ErrorCode, "ReadTimeout #3");
67 Assert.Fail ("ReadTimeout #4");