Beispiel #1
0
        private void ProcessReceivedData(int dataStartOffset, int totalReceivedDataSize, int alreadyProcessedDataSize,
                                         AsyncUserToken token, byte[] buffer)
        {
            while (true)
            {
                if (alreadyProcessedDataSize >= totalReceivedDataSize)
                {
                    return;
                }

                if (token.MessageSize == null)
                {
                    if (totalReceivedDataSize - alreadyProcessedDataSize > MESSAGE_HEADER_SIZE)
                    {
                        var headerData = new byte[MESSAGE_HEADER_SIZE];
                        Buffer.BlockCopy(buffer, dataStartOffset, headerData, 0, MESSAGE_HEADER_SIZE);
                        var messageSize = BitConverter.ToInt32(headerData, 0);

                        token.MessageSize     = messageSize;
                        token.DataStartOffset = dataStartOffset + MESSAGE_HEADER_SIZE;

                        dataStartOffset           = token.DataStartOffset;
                        alreadyProcessedDataSize += MESSAGE_HEADER_SIZE;
                        continue;
                    }
                }
                else
                {
                    var messageSize = token.MessageSize.Value;
                    if (totalReceivedDataSize - alreadyProcessedDataSize >= messageSize)
                    {
                        var messageData = new byte[messageSize];
                        Buffer.BlockCopy(buffer, dataStartOffset, messageData, 0, messageSize);
                        ProcessMessage(messageData, token);

                        token.DataStartOffset = dataStartOffset + messageSize;
                        token.MessageSize     = null;

                        dataStartOffset           = token.DataStartOffset;
                        alreadyProcessedDataSize += messageSize;
                        continue;
                    }
                }

                break;
            }
        }
Beispiel #2
0
 private void ProcessMessage(byte[] messageData, AsyncUserToken token, SocketAsyncEventArgs e)
 {
     this.ReceivedMessage?.Invoke(new MessageData {
         Message = messageData, Token = token
     });
 }
Beispiel #3
0
 private void ProcessMessage(byte[] messageData, AsyncUserToken token)
 {
     ReceivedMessage?.Invoke(new MessageData {
         Message = messageData, Token = token
     });
 }