Beispiel #1
0
        protected virtual void ProcessRequest(TcpConnection socket)
        {
            Log.LogVerbose("Processing Request");

            var requestBuffer    = s_pool.Rent(RequestBufferSize);
            var requestByteCount = socket.Receive(requestBuffer);

            if (requestByteCount == 0)
            {
                socket.Close();
                return;
            }

            var requestBytes = requestBuffer.Slice(0, requestByteCount);
            var request      = HttpRequest.Parse(requestBytes);

            Log.LogRequest(request);

            using (var responseData = new ResponseBuffer()) {
                var response = new HttpResponse(responseData);
                WriteResponse(request, response);
                s_pool.Return(requestBuffer);

                // TODO: this whole thing about segment order is very bad. It needs to be designed.
                for (int index = 0; index < responseData.Count; index++)
                {
                    var segment = responseData[index];
                    if (segment.Id == 2)
                    {
                        socket.Send(segment.Commited);
                    }
                }
                for (int index = 0; index < responseData.Count; index++)
                {
                    var segment = responseData[index];
                    if (segment.Id == 1)
                    {
                        socket.Send(segment.Commited);
                    }
                }

                socket.Close();
            }

            if (Log.IsVerbose)
            {
                Log.LogMessage(Log.Level.Verbose, "Request Processed and Response Sent", DateTime.UtcNow.Ticks);
            }
        }
Beispiel #2
0
        protected virtual void ProcessRequest(TcpConnection socket)
        {
            Log.LogVerbose("Processing Request");
            
            var requestBuffer = s_pool.Rent(RequestBufferSize);
            var requestByteCount = socket.Receive(requestBuffer);

            if(requestByteCount == 0) {
                socket.Close();
                return;
            }

            var requestBytes = requestBuffer.Slice(0, requestByteCount);
            var request = HttpRequest.Parse(requestBytes);
            Log.LogRequest(request);

            using (var responseData = new ResponseBuffer()) {
                var response = new HttpResponse(responseData);
                WriteResponse(request, response);
                s_pool.Return(requestBuffer);

                // TODO: this whole thing about segment order is very bad. It needs to be designed.
                for (int index = 0; index < responseData.Count; index++) {
                    var segment = responseData[index];
                    if (segment.Id == 2) {
                        socket.Send(segment.Commited);
                    }
                }
                for (int index = 0; index < responseData.Count; index++) {
                    var segment = responseData[index];
                    if (segment.Id == 1) {
                        socket.Send(segment.Commited);
                    }
                }

                socket.Close();
            }

            if (Log.IsVerbose)
            {
                Log.LogMessage(Log.Level.Verbose, "Request Processed and Response Sent", DateTime.UtcNow.Ticks);
            }
        }
Beispiel #3
0
 public ResponseFormatter(ResponseBuffer buffer, int segmentId)
 {
     _buffer         = buffer;
     this._segmentId = segmentId;
 }
Beispiel #4
0
 public HttpResponse(ResponseBuffer responseBuffer)
 {
     _buffer = responseBuffer;
 }
Beispiel #5
0
 public ResponseFormatter(ResponseBuffer buffer, int segmentId)
 {
     _buffer = buffer;
     this._segmentId = segmentId;
 }
Beispiel #6
0
 public HttpResponse(ResponseBuffer responseBuffer)
 {
     _buffer = responseBuffer;
 }