本文整理汇总了C#中SocketImplementationType类的典型用法代码示例。如果您正苦于以下问题:C# SocketImplementationType类的具体用法?C# SocketImplementationType怎么用?C# SocketImplementationType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SocketImplementationType类属于命名空间,在下文中一共展示了SocketImplementationType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunClient
public long RunClient(
SocketImplementationType testType,
string server,
int port,
int iterations,
int bufferSize,
int socketInstances)
{
_log.WriteLine(
_format,
"Implementation",
"Type",
"Buffer Size",
"Iterations",
"Init(ms)",
"Connect(ms)",
"SendRecv(ms)",
"Close(ms)",
"Total time");
Task[] tasks = new Task[socketInstances];
char[] charBuffer = new char[bufferSize];
for (int i = 0; i < bufferSize; i++)
{
checked
{
charBuffer[i] = (char)(i % 26 + 65);
}
}
string message = new string(charBuffer);
Stopwatch timeProgramStart = new Stopwatch();
timeProgramStart.Start();
Parallel.For(
0,
socketInstances,
(i) =>
{
var test = SocketTestClient.SocketTestClientFactory(
_log,
testType,
server,
port,
iterations,
message,
timeProgramStart);
tasks[i] = test.RunTest();
});
Task.WaitAll(tasks);
timeProgramStart.Stop();
return timeProgramStart.ElapsedMilliseconds;
}
示例2: ClientServerTest
public void ClientServerTest(
int port,
SocketImplementationType serverType,
SocketImplementationType clientType,
int iterations,
int bufferSize,
int socket_instances,
long expectedMilliseconds)
{
long milliseconds;
#if arm
iterations /= 100;
#endif
using (SocketTestServer.SocketTestServerFactory(
serverType,
socket_instances * 5,
bufferSize * 2,
new IPEndPoint(IPAddress.IPv6Loopback, port)))
{
milliseconds = RunClient(
clientType,
"localhost",
port,
iterations,
bufferSize,
socket_instances);
}
Assert.True(
milliseconds < expectedMilliseconds,
"Test execution is expected to be shorter than " + expectedMilliseconds + " but was " + milliseconds);
}
示例3: ClientServerTest
public void ClientServerTest(
SocketImplementationType serverType,
SocketImplementationType clientType,
int iterations,
int bufferSize,
int socketInstances,
long expectedMilliseconds)
{
// NOTE: port '0' below indicates that the server should bind to an anonymous port.
ClientServerTest(0, serverType, clientType, iterations, bufferSize, socketInstances, expectedMilliseconds);
}
示例4: Socket_ConnectDnsEndPoint_Success
public void Socket_ConnectDnsEndPoint_Success(SocketImplementationType type)
{
int port;
SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(new DnsEndPoint("localhost", port));
sock.Dispose();
server.Dispose();
}
示例5: SocketTestServerFactory
public static SocketTestServer SocketTestServerFactory(
SocketImplementationType type,
int numConnections,
int receiveBufferSize,
IPAddress address,
out int port)
{
SocketTestServer server = SocketTestServerFactory(type, numConnections, receiveBufferSize, new IPEndPoint(address, 0));
port = server.Port;
return server;
}
示例6: Unix_NotSupported_ThrowsPlatformNotSupportedException
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));
}
}
示例7: Disposed_Throw
public void Disposed_Throw(SocketImplementationType type)
{
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));
sock.Dispose();
Assert.Throws<ObjectDisposedException>(() =>
{
sock.SendPacketsAsync(new SocketAsyncEventArgs());
});
}
}
}
示例8: ConnectEx_Success
public void ConnectEx_Success(SocketImplementationType type)
{
Assert.True(Capability.IPv4Support() && Capability.IPv6Support());
int port;
SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port);
int port6;
SocketTestServer server6 = SocketTestServer.SocketTestServerFactory(type, IPAddress.IPv6Loopback, out port6);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, port);
args.Completed += OnConnectAsyncCompleted;
ManualResetEvent complete = new ManualResetEvent(false);
args.UserToken = complete;
Assert.True(sock.ConnectAsync(args));
Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "IPv4: Timed out while waiting for connection");
Assert.True(args.SocketError == SocketError.Success);
sock.Dispose();
sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
args.RemoteEndPoint = new IPEndPoint(IPAddress.IPv6Loopback, port6);
complete.Reset();
Assert.True(sock.ConnectAsync(args));
Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "IPv6: Timed out while waiting for connection");
Assert.True(args.SocketError == SocketError.Success);
}
finally
{
sock.Dispose();
server.Dispose();
server6.Dispose();
}
}
示例9: ConnectAsync_IPv6_Success
public void ConnectAsync_IPv6_Success(SocketImplementationType type)
{
Assert.True(Capability.IPv6Support());
AutoResetEvent completed = new AutoResetEvent(false);
int port;
using (SocketTestServer.SocketTestServerFactory(type, IPAddress.IPv6Loopback, out port))
{
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.RemoteEndPoint = new IPEndPoint(IPAddress.IPv6Loopback, port);
args.Completed += OnConnectCompleted;
args.UserToken = completed;
using (Socket client = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
{
Assert.True(client.ConnectAsync(args));
Assert.True(completed.WaitOne(TestSettings.PassingTestTimeout), "IPv6: Timed out while waiting for connection");
Assert.Equal<SocketError>(SocketError.Success, args.SocketError);
}
}
}
示例10: SocketTestClientFactory
public static SocketTestClient SocketTestClientFactory(
ITestOutputHelper log,
SocketImplementationType type,
string server,
int port,
int iterations,
string message,
Stopwatch timeProgramStart)
{
switch (type)
{
case SocketImplementationType.APM:
var socketAPM = new SocketTestClientAPM(log, server, port, iterations, message, timeProgramStart);
log.WriteLine(socketAPM.GetHashCode() + " SocketTestClientAPM(..)");
return socketAPM;
case SocketImplementationType.Async:
var socketAsync = new SocketTestClientAsync(log, server, port, iterations, message, timeProgramStart);
log.WriteLine(socketAsync.GetHashCode() + " SocketTestClientAsync(..)");
return socketAsync;
default:
throw new ArgumentOutOfRangeException(nameof(type));
}
}
示例11: NullArgs_Throw
public void NullArgs_Throw(SocketImplementationType type)
{
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));
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() =>
{
sock.SendPacketsAsync(null);
});
Assert.Equal("e", ex.ParamName);
}
}
}
示例12: EmptyBuffer_Ignored
public void EmptyBuffer_Ignored(SocketImplementationType type)
{
SendPackets(type, new SendPacketsElement(new byte[0]), 0);
}
示例13: BufferZeroCount_Ignored
public void BufferZeroCount_Ignored(SocketImplementationType type)
{
SendPackets(type, new SendPacketsElement(new byte[10], 4, 0), 0);
}
示例14: SendPackets
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);
}
}
}
}
示例15: SendPacketsElement_FileLargeCount_Throws
public void SendPacketsElement_FileLargeCount_Throws(SocketImplementationType type)
{
// Length is validated on Send
SendPackets(type, new SendPacketsElement(TestFileName, 5, 10000), SocketError.InvalidArgument, 0);
}