Beispiel #1
0
        /// <summary>
        /// Sends the specified message.
        /// </summary>
        internal static void Send(PiranhaMessage message)
        {
            if (message.Connection.IsConnected)
            {
                SocketAsyncEventArgs writeEvent = ServerConnection.WritePool.Dequeue() ?? new SocketAsyncEventArgs
                {
                    DisconnectReuseSocket = false
                };

                writeEvent.SetBuffer(message.ToArray(), message.Offset, message.Length + 7 - message.Offset);

                writeEvent.AcceptSocket   = message.Connection.Socket;
                writeEvent.RemoteEndPoint = message.Connection.EndPoint;
                writeEvent.UserToken      = message.Connection.Token;

                if (!message.Connection.Socket.SendAsync(writeEvent))
                {
                    ServerConnection.ProcessSend(message, writeEvent);
                }
            }
            else
            {
                ServerConnection.Disconnect(message.Connection?.Token?.Args);
            }
        }