internal static TcpConnection CreateConnectingTcpConnection(IPEndPoint remoteEndPoint,
TcpClientConnector connector,
Action <TcpConnection> onConnectionEstablished,
Action <TcpConnection, SocketError> onConnectionFailed)
{
var connection = new TcpConnection(remoteEndPoint);
connector.InitConnect(remoteEndPoint,
(_, socket) =>
{
connection.InitSocket(socket);
if (onConnectionEstablished != null)
{
onConnectionEstablished(connection);
}
connection.TrySend();
},
(_, socketError) =>
{
if (onConnectionFailed != null)
{
onConnectionFailed(connection, socketError);
}
});
return(connection);
}