internal IntradomainChannel(IntradomainSocket socket, IMessageSerializer serializer) { Serializer = serializer; _socket = socket; _connectionManager = IntradomainConnectionManager.Instance; }
public void Disconnect(IntradomainSocket socket) { if (string.IsNullOrEmpty(socket.ConnectionId)) { return; } Enforce.IsTrue(socket.Type != SocketType.Listener, nameof(socket)); lock (_locker) { if (!_connections.ContainsKey(socket.ConnectionId)) { return; } var connection = _connections[socket.ConnectionId]; if (socket.Type == SocketType.Client) { connection.DisconnectClient(); } if (socket.Type == SocketType.Server) { connection.DisconnectServer(); } if (connection.IsCompletelyDisconnected()) { _connections.Remove(socket.ConnectionId); } } }
internal IntradomainChannel(IntradomainSocket socket, IMessageSerializer serializer, ChannelSettings channelSettings = null, IntradomainConnectionSettings connectionSettings = null, ISecurityWrapper serverSecurityWrapper = null) : base(socket, serializer, channelSettings, connectionSettings, serverSecurityWrapper) { }
internal IntradomainChannel(IntradomainEndpoint endpoint, SocketType socketType, IMessageSerializer serializer) { Serializer = serializer; _endpoint = endpoint; _socket = new IntradomainSocket(socketType, endpoint.Hub); _connectionManager = IntradomainConnectionManager.Instance; }
public Stream GetStream(IntradomainSocket socket) { lock (_locker) { if (_connections.ContainsKey(socket.ConnectionId)) { return(_connections[socket.ConnectionId].GetStream(socket)); } throw new ArgumentException(nameof(socket)); } }
internal static IntradomainChannel CreateAndOpen(AutoResetEvent channelCreatedEvent, IntradomainSocket socket, IMessageSerializer serializer, ChannelSettings channelSettings = null, IntradomainConnectionSettings connectionSettings = null, ISecurityWrapper serverSecurityWrapper = null) { var result = new IntradomainChannel(socket, serializer, channelSettings, connectionSettings, serverSecurityWrapper); EstablishConnection(result, channelCreatedEvent, socket, connectionSettings?.ConnectTimeout ?? IntradomainConnectionSettingsBuilder.GetDefaultSettings().ConnectTimeout); return(result); }
private static void EstablishConnection(IntradomainChannel channel, AutoResetEvent channelCreatedEvent, IntradomainSocket socket, TimeSpan connectTimeout) { // release waiting client channelCreatedEvent.Set(); channel._connectionManager.WaitForConnection(socket.ConnectionId, (int)connectTimeout.TotalMilliseconds); channel.ResponseHandshake(); }
internal IntradomainChannel(IntradomainSocket socket, IMessageSerializer serializer, ChannelSettings channelSettings = null, IntradomainConnectionSettings connectionSettings = null, ISecurityWrapper serverSecurityWrapper = null) : this(socket, serializer) { _connectionSettings = connectionSettings ?? IntradomainConnectionSettingsBuilder.GetDefaultSettings(); MaxMessageLength = channelSettings?.MaxMessageLength ?? ChannelSettings.GetDefault().MaxMessageLength; SecurityWrapper = serverSecurityWrapper; }
public Stream GetStream(IntradomainSocket endpoint) { if (ServerSocket == endpoint) { return(_serverStream); } if (ClientSocket == endpoint) { return(_clientStream); } throw new ArgumentException(nameof(endpoint)); }
public bool Connect(IntradomainSocket socket, IntradomainConnectionSettings connectionSettings = null) { if (string.IsNullOrEmpty(socket.Hub)) { return(false); } if (socket.Type != SocketType.Client) { throw new ArgumentException(nameof(socket)); } Func <IntradomainSocket, IntradomainSocket> getSocketData; lock (_locker) { if (!_listeners.ContainsKey(socket.Hub)) { return(false); } getSocketData = _listeners[socket.Hub]; } socket.ConnectionId = Guid.NewGuid().ToString(); var remoteSocket = getSocketData(socket); if (remoteSocket == null) { return(false); } lock (_locker) { var connection = new IntradomainConnetcion(remoteSocket, socket, connectionSettings ?? IntradomainConnectionSettingsBuilder.GetDefaultSettings()) { ClientSocketState = IntradomainSocketState.Connected }; _connections.Add(socket.ConnectionId, connection); _connectionCreated.Set(); return(true); } }
public void Start() { Enforce.State.FitsTo(!Active, "Already started"); _connectionManager.Listen(ListeningEndpoint.Hub, client => { lock (_locker) // clients shouldn't retrieve server sockets in parallel { ServerSocket = IntradomainSocket.ServerSocket(client.Hub, client.ConnectionId); _clientAccepted.Set(); return(ChannelCreated.WaitOne(ConnectionSettings?.ConnectTimeout ?? TimeSpan.FromMilliseconds(1000)) ? ServerSocket : null); } }); }
public IntradomainConnetcion(IntradomainSocket server, IntradomainSocket client, IntradomainConnectionSettings settings) { Enforce.NotNull(server, nameof(server)); Enforce.NotNull(client, nameof(client)); Enforce.NotNull(settings, nameof(settings)); Enforce.IsTrue(server.Type == SocketType.Server, nameof(server)); Enforce.IsTrue(client.Type == SocketType.Client, nameof(client)); Enforce.IsTrue(client.ConnectionId == server.ConnectionId, "Client and server sockets should have the same ConnectionId", nameof(client)); ServerSocket = server; ClientSocket = client; _serverStream = new IntradomainStream(settings.ReceiveTimeout); _clientStream = new IntradomainStream(settings.ReceiveTimeout); _serverStream.Partner = _clientStream; _clientStream.Partner = _serverStream; }
public bool Connected(IntradomainSocket socket) { if (string.IsNullOrEmpty(socket.ConnectionId)) { return(false); } Enforce.IsTrue(socket.Type != SocketType.Listener, nameof(socket)); lock (_locker) { if (!_connections.ContainsKey(socket.ConnectionId)) { return(false); } return(socket.Type == SocketType.Client ? _connections[socket.ConnectionId].ClientSocketState == IntradomainSocketState.Connected : _connections[socket.ConnectionId].ServerSocketState == IntradomainSocketState.Connected); } }