Exemple #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 SharedData()) {
                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);
            }
        }
Exemple #2
0
 public ResponseFormatter(SharedData data, int order)
 {
     _data = data;
     _order = order;
 }
Exemple #3
0
 public HttpResponse(SharedData responseData)
 {
     _data = responseData;
 }
 public ResponseFormatter(SharedData data, int order)
 {
     _data  = data;
     _order = order;
 }
 public HttpResponse(SharedData responseData)
 {
     _data = responseData;
 }