예제 #1
0
        private void WriteHeaderAsync([NotNull] IClientConnectionInfo connectionInfo, [NotNull] TcpMessageHeader header)
        {
            if (connectionInfo == null)
            {
                throw new ArgumentNullException("connectionInfo");
            }
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            byte[] responseBuffer = new byte[TcpMessageHeader.HeaderSize];
            header.Write(responseBuffer);
            connectionInfo.Stream.Write(responseBuffer, 0, responseBuffer.Length);
        }
예제 #2
0
        private Task WriteHeaderAsync([NotNull] IClientConnectionInfo connectionInfo, [NotNull] TcpMessageHeader header)
        {
            if (connectionInfo == null)
            {
                throw new ArgumentNullException("connectionInfo");
            }
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            TaskCompletionSource <int>   completionSource = new TaskCompletionSource <int>();
            IList <ArraySegment <byte> > headerBuffer     = this._headerBufferManager.CheckOut(TcpMessageHeader.HeaderSize);

            Debug.Assert(headerBuffer.Count == 1);
            // TODO Write header to  IList<ArraySegment<byte>>
            header.Write(headerBuffer[0].Array, headerBuffer[0].Offset);
            SendUserToken userToken = new SendUserToken(SendState.HeaderSending, completionSource, this, true);

            this._sender.SendAsync(connectionInfo.Socket, headerBuffer, TcpMessageHeader.HeaderSize, userToken, SendCallbackHandler);

            return(userToken.SendTaskCompletionSource.Task);
        }