Example #1
0
        private void session_SendComplete(object sender, SendCompleteEventArgs e)
        {
            logger.Debug("{0} response sent.", _connectionToken.Substring(0, 6));

            _lastActiveTime = DateTime.Now;

            if (_lastProcessor.ResponseBodyLength != 0)
            {
                int    length = 0;
                byte[] buffer;
                int    offset;

                try
                {
                    length = _lastProcessor.SubmitResponseBody(
                        out buffer, out offset);
                }
                catch (Exception ex)
                {
                    //exception occur while get response body from processer
                    logger.Warn("{0} exception occur while get response body from processer {1}, message: {2}",
                                _connectionToken.Substring(0, 6),
                                _lastProcessor.GetType().Name,
                                ex.Message);
                    Close();
                    return;
                }

                if (length > 0)
                {
                    _workStatus = SessionWorkStatus.SendingResponseBody;
                    _session.ContinueSendingBody(buffer, offset, length);
                    return;
                }
            }

            //close session if does not keep alive
            //NOTE::Let client to close the connection, otherwise, server will
            //generate lots of TIME_WAIT sockets

            ////if (!_serverKeepAlive)
            ////{
            ////    Close();
            ////}
            ////else
            ////{
            //continue receive next request
            _workStatus = SessionWorkStatus.ReceivingRequestHeader;
            HttpRequestHeader requestHeader = new HttpRequestHeader();

            _session.Receive(requestHeader, _bodyBuffer, 0, _bodyBuffer.Length);
            ////}
        }