Ejemplo n.º 1
0
        /// <summary>
        ///     Will fire all events according to the queued messages
        /// </summary>
        public void Work()
        {
            if (Stopped)
            {
                throw new InvalidOperationException($"{nameof(EasySocket)} was stopped");
            }
            SocketAsyncEventArgs result;

            while (!_acceptedSockets.IsEmpty)
            {
                if (_acceptedSockets.TryDequeue(out result))
                {
                    OnAccepted?.Invoke(Socket, result);
                }
            }

            while (!_receivedData.IsEmpty)
            {
                if (_receivedData.TryDequeue(out result))
                {
                    OnReceived?.Invoke(Socket, result);
                }
            }

            while (!_receivedFromData.IsEmpty)
            {
                if (_receivedFromData.TryDequeue(out result))
                {
                    OnReceivedFrom?.Invoke(Socket, result);
                }
            }

            while (!_receivedMessageFromData.IsEmpty)
            {
                if (_receivedMessageFromData.TryDequeue(out result))
                {
                    OnReceivedMessageFrom?.Invoke(Socket, result);
                }
            }

            while (!_sendComplete.IsEmpty)
            {
                if (_sendComplete.TryDequeue(out result))
                {
                    OnSent?.Invoke(Socket, result);
                }
            }

            while (!_sendToComplete.IsEmpty)
            {
                if (_sendToComplete.TryDequeue(out result))
                {
                    OnSentTo?.Invoke(Socket, result);
                }
            }
        }
Ejemplo n.º 2
0
 private void OnReceivedMessageFromComplete(object sender, SocketAsyncEventArgs socketAsyncEventArgs)
 {
     Task.Run(() => OnReceivedMessageFrom?.Invoke(this, socketAsyncEventArgs));
     SetupReceiveMessageFrom();
 }