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
23 [ExpectedException(typeof(IOException))]
24 public void NetworkStreamConnection ()
26 IPEndPoint ipe = new IPEndPoint(Dns.GetHostEntry ("www.google.com").AddressList [0], 80);
27 Socket s = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
29 NetworkStream ns = new NetworkStream (s);
33 public void ReadTimeout ()
35 Socket sock = new Socket (AddressFamily.InterNetwork,
38 Socket listen = new Socket (AddressFamily.InterNetwork,
41 IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 0);
46 sock.Connect (listen.LocalEndPoint);
48 NetworkStream stream = new NetworkStream (sock);
49 stream.ReadTimeout = 1000;
51 byte[] buf = new byte[1024];
54 stream.Read (buf, 0, buf.Length);
55 Assert.Fail ("ReadTimeout #1");
56 } catch (IOException ex) {
57 Exception inner = ex.InnerException;
58 SocketException sockex = inner as SocketException;
60 Assert.IsNotNull (sockex, "ReadTimeout #2");
62 /* Linux gives error 10035 (EWOULDBLOCK) here, whereas windows has 10060 (ETIMEDOUT)
63 Assert.AreEqual (10060, sockex.ErrorCode, "ReadTimeout #3");
66 Assert.Fail ("ReadTimeout #4");