private void ProcessDatagram(Message msg, Connection.Connection connection) { if (msg.Header.Reliable) { connection.ReceiveReliable(msg); if (!msg.Header.Sequenced && !msg.Header.Ordered) { if (connection.HasAlreadyArrived(msg)) { return; } } } if (msg.Header.Sequenced) { if (connection.IsMessageInItsOrder(msg.Header.Type, msg.Header.MessageId)) { ProcessHandler(msg, connection); } } else if (msg.Header.Ordered) { var toInvoke = connection.MessagesToInvoke(msg); if (toInvoke == null) { return; } ProcessHandlerList(toInvoke, connection); } else { ProcessHandler(msg, connection); } }
internal void RowSend(Message msg, Connection.Connection con) { con.MarkToSend(msg); if (msg.Header.Reliable) { con.StoreReliable(msg); } }
private void SendToken(Connection.Connection con) { var msg = new Message((short)MessageType.Token, Mode.None) { ConnectionToken = con.Token }; Send(msg, con); }
/// <summary> /// Sending message to specific connection /// </summary> /// <param name="msg">Message to send</param> /// <param name="con">Destination connection</param> public void Send(Message msg, Connection.Connection con) { msg.ConnectionToken = con.Token; if (msg.Header.Type != (short)MessageType.Ack) { msg.MessageId = con.GetMessageId(msg); } con.MarkToSend(msg); if (msg.Header.Reliable) { con.StoreReliable(msg); } }
private static void InvokeHandler(ReceiveHandler handler, Message msg, Connection.Connection connection) { var async = handler.GetType().GetCustomAttributes(typeof(AsyncOperationAttribute), false).Length > 0; if (async) { ThreadPool.QueueUserWorkItem((o) => handler.Invoke(msg, connection)); } else { handler.Invoke(msg, connection); } }
private static void InvokeHandler(ReceiveHandler handler, Message msg, Connection.Connection connection) { if (Dispatcher.IsInitialized) { Dispatcher.RunOnMainThread(handler, msg, connection); return; } var async = handler.GetType().GetCustomAttributes(typeof(AsyncOperationAttribute), false).Length > 0; if (async) { ThreadPool.QueueUserWorkItem((o) => handler.Invoke(msg, connection)); } else { handler.Invoke(msg, connection); } }
private void ProcessHandlerList(IList <Message> messages, Connection.Connection connection) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } IList <ReceiveHandler> handlers = null; if (messages.Count == 0) { return; } var msg = messages[0]; lock (_receiveHandlers) { if (_receiveHandlers.ContainsKey(msg.Header.Type)) { handlers = _receiveHandlers[msg.Header.Type]; } } if (handlers == null) { return; } connection = _connectionManager[msg.Header.ConnectionToken]; foreach (var h in handlers) { foreach (var m in messages) { try { InvokeHandler(h, m, connection); } catch (Exception ex) { OnException.Invoke(ex); } } } connection.UpdateActivity(); }
private void ProcessHandler(Message msg, Connection.Connection connection) { connection.InvokeIfBinded(msg); IList <ReceiveHandler> handlers = null; lock (_receiveHandlers) { if (_receiveHandlers.ContainsKey(msg.Header.Type)) { handlers = _receiveHandlers[msg.Header.Type]; } } if (handlers == null) { return; } foreach (var h in handlers) { InvokeHandler(h, msg, connection); } connection.UpdateActivity(); }
/// <summary> /// Disconnect connection /// </summary> /// <param name="con">Connection to disconnect</param> public void ForceDisconnect(Connection.Connection con) { _connectionManager.Remove(con.Token); }