public void Socket_ConnectAsyncDnsEndPoint_SetSocketProperties_Success(SocketImplementationType type) { Assert.True(Capability.IPv4Support()); int port; using (SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port)) using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { sock.LingerState = new LingerOption(false, 0); sock.NoDelay = true; sock.ReceiveBufferSize = 1024; sock.ReceiveTimeout = 100; sock.SendBufferSize = 1024; sock.SendTimeout = 100; SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.RemoteEndPoint = new DnsEndPoint("localhost", port); args.Completed += OnConnectAsyncCompleted; ManualResetEvent complete = new ManualResetEvent(false); args.UserToken = complete; bool willRaiseEvent = sock.ConnectAsync(args); if (willRaiseEvent) { Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection"); complete.Dispose(); // only dispose on success as we know we're done with the instance } Assert.Equal(SocketError.Success, args.SocketError); Assert.Null(args.ConnectByNameError); } }
public void Disconnect_Success() { AutoResetEvent completed = new AutoResetEvent(false); IPEndPoint loopback = new IPEndPoint(IPAddress.Loopback, 0); using (var server1 = SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, loopback)) using (var server2 = SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, loopback)) { SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.Completed += OnCompleted; args.UserToken = completed; args.RemoteEndPoint = server1.EndPoint; args.DisconnectReuseSocket = true; using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { Assert.True(client.ConnectAsync(args)); completed.WaitOne(); Assert.Equal(SocketError.Success, args.SocketError); client.Disconnect(true); args.RemoteEndPoint = server2.EndPoint; Assert.True(client.ConnectAsync(args)); completed.WaitOne(); Assert.Equal(SocketError.Success, args.SocketError); } } }
private void SendPackets(SocketImplementationType type, SendPacketsElement[] elements, SocketError expectedResut, int bytesExpected) { Assert.True(Capability.IPv6Support()); EventWaitHandle completed = new ManualResetEvent(false); int port; using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port)) { using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { sock.Connect(new IPEndPoint(_serverAddress, port)); using (SocketAsyncEventArgs args = new SocketAsyncEventArgs()) { args.Completed += OnCompleted; args.UserToken = completed; args.SendPacketsElements = elements; if (sock.SendPacketsAsync(args)) { Assert.True(completed.WaitOne(TestSettings.PassingTestTimeout), "Timed out"); } Assert.Equal(expectedResut, args.SocketError); Assert.Equal(bytesExpected, args.BytesTransferred); } } } }
public void Socket_ConnectAsyncDnsEndPoint_Success(SocketImplementationType type) { Assert.True(Capability.IPv4Support()); int port; using (SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port)) using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) using (ManualResetEvent complete = new ManualResetEvent(false)) { SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.RemoteEndPoint = new DnsEndPoint("localhost", port); args.Completed += OnConnectAsyncCompleted; args.UserToken = complete; bool willRaiseEvent = sock.ConnectAsync(args); if (willRaiseEvent) { Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection"); } Assert.Equal(SocketError.Success, args.SocketError); Assert.Null(args.ConnectByNameError); } }
public void Success() { AutoResetEvent completed = new AutoResetEvent(false); if (Socket.OSSupportsIPv4) { int port, port1; using (SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port)) using (SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port1)) { SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.Completed += OnCompleted; args.UserToken = completed; args.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, port); args.DisconnectReuseSocket = true; Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Assert.True(client.ConnectAsync(args)); Assert.True(completed.WaitOne(Configuration.PassingTestTimeout), "Timed out while waiting for connection"); Assert.Equal <SocketError>(SocketError.Success, args.SocketError); client.Disconnect(true); args.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, port1); Assert.True(client.ConnectAsync(args)); Assert.True(completed.WaitOne(Configuration.PassingTestTimeout), "Timed out while waiting for connection"); Assert.Equal <SocketError>(SocketError.Success, args.SocketError); client.Dispose(); } } }
public async Task Connect_DualMode_MultiAddressFamilyConnect_RetrievedEndPoints_Success() { if (!SupportsMultiConnect) { return; } int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback, out port)) using (Socket client = new Socket(SocketType.Stream, ProtocolType.Tcp)) { Assert.True(client.DualMode); Task connectTask = MultiConnectAsync(client, new IPAddress[] { IPAddress.IPv6Loopback, IPAddress.Loopback }, port); await connectTask; var localEndPoint = client.LocalEndPoint as IPEndPoint; Assert.NotNull(localEndPoint); Assert.Equal(IPAddress.Loopback.MapToIPv6(), localEndPoint.Address); var remoteEndPoint = client.RemoteEndPoint as IPEndPoint; Assert.NotNull(remoteEndPoint); Assert.Equal(IPAddress.Loopback.MapToIPv6(), remoteEndPoint.Address); } }
public void Socket_ConnectAsyncDnsEndPoint_Success() { Assert.True(Capability.IPv4Support()); int port; SocketTestServer server = SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port); SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.RemoteEndPoint = new DnsEndPoint("localhost", port); args.Completed += OnConnectAsyncCompleted; ManualResetEvent complete = new ManualResetEvent(false); args.UserToken = complete; Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Assert.True(sock.ConnectAsync(args)); complete.WaitOne(); Assert.Equal(SocketError.Success, args.SocketError); Assert.Null(args.ConnectByNameError); complete.Dispose(); sock.Dispose(); server.Dispose(); }
public async Task Connect_DualMode_DnsConnect_RetrievedEndPoints_Success() { var localhostAddresses = Dns.GetHostAddresses("localhost"); if (Array.IndexOf(localhostAddresses, IPAddress.Loopback) == -1 || Array.IndexOf(localhostAddresses, IPAddress.IPv6Loopback) == -1) { return; } int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback, out port)) using (Socket client = new Socket(SocketType.Stream, ProtocolType.Tcp)) { Assert.True(client.DualMode); Task connectTask = ConnectAsync(client, new DnsEndPoint("localhost", port)); await connectTask; var localEndPoint = client.LocalEndPoint as IPEndPoint; Assert.NotNull(localEndPoint); Assert.True(localEndPoint.Address.Equals(IPAddress.IPv6Loopback) || localEndPoint.Address.Equals(IPAddress.Loopback.MapToIPv6())); var remoteEndPoint = client.RemoteEndPoint as IPEndPoint; Assert.NotNull(remoteEndPoint); Assert.Equal(IPAddress.Loopback.MapToIPv6(), remoteEndPoint.Address); } }
public void Socket_ConnectAsyncDnsEndPoint_Success() { int port; SocketTestServer server = SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port); SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.RemoteEndPoint = new DnsEndPoint("localhost", port); args.Completed += OnConnectAsyncCompleted; ManualResetEvent complete = new ManualResetEvent(false); args.UserToken = complete; Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); bool willRaiseEvent = sock.ConnectAsync(args); if (willRaiseEvent) { Assert.True(complete.WaitOne(Configuration.PassingTestTimeout), "Timed out while waiting for connection"); } Assert.Equal(SocketError.Success, args.SocketError); Assert.Null(args.ConnectByNameError); complete.Dispose(); sock.Dispose(); server.Dispose(); }
public void Socket_ConnectDnsEndPoint_Success(SocketImplementationType type) { int port; using (SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port)) using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { sock.Connect(new DnsEndPoint("localhost", port)); } }
public async Task ConnectTaskAsync_IPAddresss_Success(AddressFamily family) { int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, family == AddressFamily.InterNetwork ? IPAddress.Loopback : IPAddress.IPv6Loopback, out port)) using (Socket client = new Socket(family, SocketType.Stream, ProtocolType.Tcp)) { await client.ConnectAsync(new IPAddress[] { IPAddress.Loopback, IPAddress.IPv6Loopback }, port); Assert.True(client.Connected); } }
public void Socket_BeginConnectDnsEndPoint_Success(SocketImplementationType type) { int port; using (SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port)) using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { IAsyncResult result = sock.BeginConnect(new DnsEndPoint("localhost", port), null, null); sock.EndConnect(result); Assert.Throws <InvalidOperationException>(() => sock.EndConnect(result)); // validate can't call end twice } }
public void Socket_BeginConnectDnsEndPoint_Success(SocketImplementationType type) { int port; using (SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port)) using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { IAsyncResult result = sock.BeginConnect(new DnsEndPoint("localhost", port), null, null); sock.EndConnect(result); Assert.True(sock.Connected); } }
public async Task Socket_ConnectAsyncUnixDomainSocketEndPoint_Success() { string path = null; SocketTestServer server = null; UnixDomainSocketEndPoint endPoint = null; for (int attempt = 0; attempt < 5; attempt++) { path = GetRandomNonExistingFilePath(); endPoint = new UnixDomainSocketEndPoint(path); try { server = SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, endPoint, ProtocolType.Unspecified); break; } catch (SocketException) { //Path selection is contingent on a successful Bind(). //If it fails, the next iteration will try another path. } } try { Assert.NotNull(server); SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.RemoteEndPoint = endPoint; args.Completed += (s, e) => ((TaskCompletionSource)e.UserToken).SetResult(); var complete = new TaskCompletionSource(); args.UserToken = complete; using (Socket sock = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified)) { bool willRaiseEvent = sock.ConnectAsync(args); if (willRaiseEvent) { await complete.Task; } Assert.Equal(SocketError.Success, args.SocketError); Assert.Null(args.ConnectByNameError); } } finally { server.Dispose(); try { File.Delete(path); } catch { } } }
public void Socket_ConnectDnsEndPoint_Success() { int port; SocketTestServer server = SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port); Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sock.Connect(new DnsEndPoint("localhost", port)); sock.Dispose(); server.Dispose(); }
public void Unix_NotSupported_ThrowsPlatformNotSupportedException(SocketImplementationType type) { int port; using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port)) using (var sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) using (var args = new SocketAsyncEventArgs()) { sock.Connect(new IPEndPoint(_serverAddress, port)); args.SendPacketsElements = new SendPacketsElement[1]; Assert.Throws <PlatformNotSupportedException>(() => sock.SendPacketsAsync(args)); } }
public async Task Connect_Success(IPAddress listenAt) { int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, listenAt, out port)) { using (Socket client = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) { Task connectTask = ConnectAsync(client, new IPEndPoint(listenAt, port)); await connectTask; Assert.True(client.Connected); } } }
public async Task Connect_AfterDisconnect_Fails() { int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback, out port)) using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { await client.ConnectAsync(IPAddress.Loopback, port); client.Disconnect(reuseSocket: false); Assert.Throws <InvalidOperationException>(() => client.Connect(IPAddress.Loopback, port)); Assert.Throws <InvalidOperationException>(() => client.Connect(new IPEndPoint(IPAddress.Loopback, port))); } }
public void Connect_Success(IPAddress listenAt) { int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, listenAt, out port)) { using (Socket client = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) { Task connectTask = ConnectAsync(client, new IPEndPoint(listenAt, port)); Assert.True(connectTask.Wait(TestSettings.PassingTestTimeout), "IPv4: Timed out while waiting for connection"); Assert.True(client.Connected); } } }
public void Socket_ConnectAsyncUnixDomainSocketEndPoint_Success() { string path = null; SocketTestServer server = null; UnixDomainSocketEndPoint endPoint = null; for (int attempt = 0; attempt < 5; attempt++) { path = GetRandomNonExistingFilePath(); endPoint = new UnixDomainSocketEndPoint(path); try { server = SocketTestServer.SocketTestServerFactory(endPoint, ProtocolType.Unspecified); break; } catch (SocketException) { // Path selection is contingent on a successful Bind(). // If it fails, the next iteration will try another path. } } try { Assert.NotNull(server); SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.RemoteEndPoint = endPoint; args.Completed += OnConnectAsyncCompleted; ManualResetEvent complete = new ManualResetEvent(false); args.UserToken = complete; Socket sock = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); Assert.True(sock.ConnectAsync(args)); complete.WaitOne(); Assert.Equal(SocketError.Success, args.SocketError); Assert.Null(args.ConnectByNameError); complete.Dispose(); sock.Dispose(); server.Dispose(); } finally { File.Delete(path); } }
public void NullArgs_Throw() { int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, _serverAddress, out port)) { using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { sock.Connect(new IPEndPoint(_serverAddress, port)); AssertExtensions.Throws <ArgumentNullException>("e", () => sock.SendPacketsAsync(null)); } } }
public void Socket_StaticConnectAsync_Success() { Assert.True(Capability.IPv4Support() && Capability.IPv6Support()); int port; SocketTestServer server4 = SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port); int port6; SocketTestServer server6 = SocketTestServer.SocketTestServerFactory(IPAddress.IPv6Loopback, out port6); SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.RemoteEndPoint = new DnsEndPoint("localhost", port); args.Completed += OnConnectAsyncCompleted; ManualResetEvent complete = new ManualResetEvent(false); args.UserToken = complete; Assert.True(Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args)); complete.WaitOne(); Assert.Equal(SocketError.Success, args.SocketError); Assert.Null(args.ConnectByNameError); Assert.NotNull(args.ConnectSocket); Assert.True(args.ConnectSocket.AddressFamily == AddressFamily.InterNetwork); Assert.True(args.ConnectSocket.Connected); args.ConnectSocket.Dispose(); args.RemoteEndPoint = new DnsEndPoint("localhost", port6); complete.Reset(); Assert.True(Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args)); complete.WaitOne(); Assert.Equal(SocketError.Success, args.SocketError); Assert.Null(args.ConnectByNameError); Assert.NotNull(args.ConnectSocket); Assert.True(args.ConnectSocket.AddressFamily == AddressFamily.InterNetworkV6); Assert.True(args.ConnectSocket.Connected); args.ConnectSocket.Dispose(); server4.Dispose(); server6.Dispose(); }
public async Task Connect_OnConnectedSocket_Fails() { int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback, out port)) using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { await ConnectAsync(client, new IPEndPoint(IPAddress.Loopback, port)); // In the sync case, we throw a derived exception here, so need to use ThrowsAnyAsync SocketException se = await Assert.ThrowsAnyAsync <SocketException>(() => ConnectAsync(client, new IPEndPoint(IPAddress.Loopback, port))); Assert.Equal(SocketError.IsConnected, se.SocketErrorCode); } }
public void BufferZeroCountThenNormal_ZeroCountIgnored() { Assert.True(Capability.IPv6Support()); EventWaitHandle completed = new ManualResetEvent(false); int port; using (SocketTestServer.SocketTestServerFactory(_serverAddress, out port)) { using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { sock.Connect(new IPEndPoint(_serverAddress, port)); using (SocketAsyncEventArgs args = new SocketAsyncEventArgs()) { args.Completed += OnCompleted; args.UserToken = completed; // First do an empty send, ignored args.SendPacketsElements = new SendPacketsElement[] { new SendPacketsElement(new byte[5], 3, 0) }; if (sock.SendPacketsAsync(args)) { Assert.True(completed.WaitOne(Configuration.PassingTestTimeout), "Timed out"); } Assert.Equal(SocketError.Success, args.SocketError); Assert.Equal(0, args.BytesTransferred); completed.Reset(); // Now do a real send args.SendPacketsElements = new SendPacketsElement[] { new SendPacketsElement(new byte[5], 1, 4) }; if (sock.SendPacketsAsync(args)) { Assert.True(completed.WaitOne(Configuration.PassingTestTimeout), "Timed out"); } Assert.Equal(SocketError.Success, args.SocketError); Assert.Equal(4, args.BytesTransferred); } } } }
public void Socket_StaticConnectAsync_Success(SocketImplementationType type) { Assert.True(Capability.IPv4Support() && Capability.IPv6Support()); int port4, port6; using (SocketTestServer server4 = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port4)) using (SocketTestServer server6 = SocketTestServer.SocketTestServerFactory(type, IPAddress.IPv6Loopback, out port6)) { SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.RemoteEndPoint = new DnsEndPoint("localhost", port4); args.Completed += OnConnectAsyncCompleted; ManualResetEvent complete = new ManualResetEvent(false); args.UserToken = complete; if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args)) { Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection"); } Assert.Equal(SocketError.Success, args.SocketError); Assert.Null(args.ConnectByNameError); Assert.NotNull(args.ConnectSocket); Assert.True(args.ConnectSocket.AddressFamily == AddressFamily.InterNetwork); Assert.True(args.ConnectSocket.Connected); args.ConnectSocket.Dispose(); args.RemoteEndPoint = new DnsEndPoint("localhost", port6); complete.Reset(); if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args)) { Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection"); } complete.Dispose(); // only dispose on success as we know we're done with the instance Assert.Equal(SocketError.Success, args.SocketError); Assert.Null(args.ConnectByNameError); Assert.NotNull(args.ConnectSocket); Assert.True(args.ConnectSocket.AddressFamily == AddressFamily.InterNetworkV6); Assert.True(args.ConnectSocket.Connected); args.ConnectSocket.Dispose(); } }
public void Socket_ConnectDnsEndPoint_SetSocketProperties_Success(SocketImplementationType type) { int port; using (SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port)) using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { sock.LingerState = new LingerOption(false, 0); sock.NoDelay = true; sock.ReceiveBufferSize = 1024; sock.ReceiveTimeout = 100; sock.SendBufferSize = 1024; sock.SendTimeout = 100; sock.Connect(new DnsEndPoint("localhost", port)); } }
private void SendPackets(SocketImplementationType type, SendPacketsElement element, TransmitFileOptions flags, int bytesExpected) { Assert.True(Capability.IPv6Support()); EventWaitHandle completed = new ManualResetEvent(false); int port; using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port)) { using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { sock.Connect(new IPEndPoint(_serverAddress, port)); using (SocketAsyncEventArgs args = new SocketAsyncEventArgs()) { args.Completed += OnCompleted; args.UserToken = completed; args.SendPacketsElements = new[] { element }; args.SendPacketsFlags = flags; if (sock.SendPacketsAsync(args)) { Assert.True(completed.WaitOne(TestSettings.PassingTestTimeout), "Timed out"); } Assert.Equal(SocketError.Success, args.SocketError); Assert.Equal(bytesExpected, args.BytesTransferred); } switch (flags) { case TransmitFileOptions.Disconnect: // Sending data again throws with socket shut down error. Assert.Throws <SocketException>(() => { sock.Send(new byte[1] { 01 }); }); break; case TransmitFileOptions.ReuseSocket & TransmitFileOptions.Disconnect: // Able to send data again with reuse socket flag set. Assert.Equal(1, sock.Send(new byte[1] { 01 })); break; } } } }
public void Connect_MultipleIPAddresses_Success(IPAddress listenAt) { if (!SupportsMultiConnect) { return; } int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, listenAt, out port)) using (Socket client = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) { Task connectTask = MultiConnectAsync(client, new IPAddress[] { IPAddress.Loopback, IPAddress.IPv6Loopback }, port); Assert.True(connectTask.Wait(TestSettings.PassingTestTimeout), "Timed out while waiting for connection"); Assert.True(client.Connected); } }
public async Task Connect_MultipleIPAddresses_Success(IPAddress listenAt) { if (!SupportsMultiConnect) { return; } int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, listenAt, out port)) using (Socket client = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) { Task connectTask = MultiConnectAsync(client, new IPAddress[] { IPAddress.Loopback, IPAddress.IPv6Loopback }, port); await connectTask; Assert.True(client.Connected); } }
public void Disposed_Throw() { int port; using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, _serverAddress, out port)) { using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)) { sock.Connect(new IPEndPoint(_serverAddress, port)); sock.Dispose(); Assert.Throws <ObjectDisposedException>(() => { sock.SendPacketsAsync(new SocketAsyncEventArgs()); }); } } }