NetworkStreamTest.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // System.Net.Sockets.NetworkStreamTest.cs
  2. //
  3. // Author:
  4. // Dick Porter ([email protected])
  5. //
  6. // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
  7. //
  8. using System.Net.Sockets;
  9. using System.Net;
  10. using System;
  11. using System.IO;
  12. using NUnit.Framework;
  13. namespace MonoTests.System.Net.Sockets
  14. {
  15. [TestFixture]
  16. public class NetworkStreamTest
  17. {
  18. #if NET_2_0
  19. [Test]
  20. public void ReadTimeout ()
  21. {
  22. Socket sock = new Socket (AddressFamily.InterNetwork,
  23. SocketType.Stream,
  24. ProtocolType.Tcp);
  25. Socket listen = new Socket (AddressFamily.InterNetwork,
  26. SocketType.Stream,
  27. ProtocolType.Tcp);
  28. IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 0);
  29. listen.Bind (ep);
  30. listen.Listen (1);
  31. sock.Connect (listen.LocalEndPoint);
  32. NetworkStream stream = new NetworkStream (sock);
  33. stream.ReadTimeout = 1000;
  34. byte[] buf = new byte[1024];
  35. try {
  36. stream.Read (buf, 0, buf.Length);
  37. Assert.Fail ("ReadTimeout #1");
  38. } catch (IOException ex) {
  39. Exception inner = ex.InnerException;
  40. SocketException sockex = inner as SocketException;
  41. Assert.IsNotNull (sockex, "ReadTimeout #2");
  42. /* Linux gives error 10035 (EWOULDBLOCK) here, whereas windows has 10060 (ETIMEDOUT)
  43. Assertion.AssertEquals ("ReadTimeout #3",
  44. 10060,
  45. sockex.ErrorCode);
  46. */
  47. } catch {
  48. Assert.Fail ("ReadTimeout #4");
  49. } finally {
  50. stream.Close ();
  51. sock.Close ();
  52. listen.Close ();
  53. }
  54. }
  55. #endif
  56. }
  57. }