Example #1
0
        public bool ShouldPass(int channel, IProtocolHeader protocolHeader)
        {
            _expectationManager.Get <ProtocolHeaderExpectation>(channel);

            _expectationManager.Set(channel, new MethodExpectation(_expectedMethodManager.GetExpectingMethodsFor <IProtocolHeader>()));
            return(true);
        }
 public SendCompleteEventArgs(
     IProtocolHeader lastSendHeader,
     int sendedLength,
     long totalSendedLength,
     long totalPlanSendingLength)
 {
     _lastSendHeader         = lastSendHeader;
     _sendedLength           = sendedLength;
     _totalSendedLength      = totalSendedLength;
     _totalPlanSendingLength = totalPlanSendingLength;
 }
Example #3
0
 public ReceiveBodyCompleteEventArgs(
     IProtocolHeader lastReceiveHeader,
     byte[] data,
     int dataLength,
     int dataOffset,
     long totalHasReceivedLength,
     long totalPlanReceivingLength)
 {
     _lastReceiveHeader = lastReceiveHeader;
     _data                     = data;
     _dataLength               = dataLength;
     _dataOffset               = dataOffset;
     _totalHasReceivedLength   = totalHasReceivedLength;
     _totalPlanReceivingLength = totalPlanReceivingLength;
 }
        /// <summary>
        /// Send header only (without body)
        /// </summary>
        /// <param name="header"></param>
        public void Send(IProtocolHeader header)
        {
            if (_isClosing)
            {
                throw new AsyncSocketException("Connection has closed");
            }

            _lastSendHeader  = header;
            _isSendingHeader = true;
            _toBeSendData    = null;
            _sendingProgress.Reset();

            byte[]          headerData = header.GetHeaderRawData();
            SocketSendState sendState  = new SocketSendState(headerData, 0, headerData.Length);

            beginSendData(sendState);
        }
        /// <summary>
        /// Send header and body at one time
        /// </summary>
        /// <param name="header"></param>
        /// <param name="data"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        public void Send(IProtocolHeader header, byte[] data, int offset, int length)
        {
            //NOTE::
            //when this operation complete, it raise SendComplete event only once when
            //the header and body all send complete.

            if (_isClosing)
            {
                throw new AsyncSocketException("Connection has closed");
            }

            _lastSendHeader  = header;
            _isSendingHeader = true;
            _toBeSendData    = new SocketSendState(data, offset, length);
            _sendingProgress.Reset();
            _sendingProgress.Total = length;

            byte[]          headerData = header.GetHeaderRawData();
            SocketSendState sendState  = new SocketSendState(headerData, 0, headerData.Length);

            beginSendData(sendState);
        }
        /// <summary>
        /// Begin receive data
        /// </summary>
        /// <param name="header"></param>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        public void Receive(IProtocolHeader header, byte[] buffer, int offset, int length)
        {
            //the buffer length must large than TRANSFER_BLOCK_LENGTH
            if (buffer.Length - offset < TRANSFER_BLOCK_LENGTH ||
                length < TRANSFER_BLOCK_LENGTH)
            {
                throw new ArgumentException("Buffer length must large than TRANSFER_BLOCK_LENGTH");
            }

            if (_isClosing)
            {
                throw new AsyncSocketException("Connection has closed");
            }

            _lastReceiveHeader = header;
            _toBeReceiveData   = new SocketReceiveState(buffer, offset, length);
            _receivingProgress.Reset();

            SocketReceiveState receiveState = new SocketReceiveState(
                _headerBuffer, 0, _headerBuffer.Length);

            beginReceiveData(receiveState);
        }
        /// <summary>
        /// Combine with 'ContinueSendingBody' method to send big data
        /// </summary>
        /// <param name="header"></param>
        /// <param name="totalPlanSendingLength"></param>
        public void Send(IProtocolHeader header, long totalPlanSendingLength)
        {
            //NOTE::
            //when need sending big data, call this method first,
            //and when this header send complete, call "ContinueSendingBody" many times
            //to send the body until all has been send.

            if (_isClosing)
            {
                throw new AsyncSocketException("Connection has closed");
            }

            _lastSendHeader  = header;
            _isSendingHeader = true;
            _toBeSendData    = null;
            _sendingProgress.Reset();
            _sendingProgress.Total = totalPlanSendingLength;

            byte[]          headerData = header.GetHeaderRawData();
            SocketSendState sendState  = new SocketSendState(headerData, 0, headerData.Length);

            beginSendData(sendState);
        }
Example #8
0
 public ReceiveHeaderCompleteEventArgs(
     IProtocolHeader lastReceiveHeader)
 {
     _lastReceiveHeader        = lastReceiveHeader;
     _totalPlanReceivingLength = 0;
 }