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