Beispiel #1
0
 public virtual void OnRecvReqLineSuccess(RequestLineInfo head)
 {
     if (RecvReqLineSuccess != null)
     {
         RecvReqLineSuccess(this, head);
     }
 }
Beispiel #2
0
 void httpParse_RecvReqLineSuccess(HttpParse arg1, RequestLineInfo arg2)
 {
 }
Beispiel #3
0
        private void endRecv(IAsyncResult result)
        {
            int recvCount = 0;

            try
            {
                recvCount = this.sock.EndReceive(result, out this.sockError);
            }
            catch
            {
                OnClose();
                return;
            }
            if (recvCount == 0)
            {
                OnClose();
                return;
            }
            this.DataList.AddRange(this.buffer.Take(recvCount));
            if (State == ParseState.inited)
            {
                int index = this.DataList.IndexOf((byte)('\n'));
                if (index != -1)
                {
                    var reqLineStr = DataList.Take(index - 1).ToArray();
                    var reqLine    = new RequestLineInfo(Encoding.ASCII.GetString(reqLineStr));
                    sourceData.AddRange(DataList.Take(index + 1).ToArray());
                    DataList.RemoveRange(0, index + 1);
                    this.ReqLine = reqLine;
                    if (reqLine != null)
                    {
                        OnRecvReqLineSuccess(reqLine);
                    }
                    State = ParseState.parseRequestLineSuccess;
                }
            }
            if (State == ParseState.parseRequestLineSuccess)
            {
                int headIndex = -1;
                for (int i = 0; i < (this.DataList.Count - 3); i++)
                {
                    if (DataList[i] == '\r' && DataList[i + 1] == '\n' && DataList[i + 2] == '\r' && DataList[i + 3] == '\n')
                    {
                        headIndex = i;
                    }
                }
                if (headIndex != -1)
                {
                    var reqHeadStr = DataList.Take(headIndex).ToArray();
                    var reqHead    = new RequestHeadInfo(Encoding.ASCII.GetString(reqHeadStr));
                    sourceData.AddRange(DataList.Take(headIndex + 4));
                    DataList.RemoveRange(0, headIndex + 4);
                    this.ReqHead = reqHead;
                    if (reqHead != null)
                    {
                        OnRecvReqHeadSuccess(reqHead);
                    }
                    State = ParseState.parseHeadSuccess;
                }
            }
            if (State == ParseState.parseHeadSuccess)
            {
                //无Content
                if (this.ReqHead.ContextLength == -1 && DataList.Count == 0)
                {
                    this.State = ParseState.parseBodySuccess;
                }
                if (this.ReqHead.ContextLength == DataList.Count)
                {
                    sourceData.AddRange(DataList.Take(DataList.Count));
                    DataList.RemoveRange(0, DataList.Count);
                    this.State = ParseState.parseBodySuccess;
                }
            }
            if (State == ParseState.parseBodySuccess)
            {
                OnRecvRequestSuccess();
                this.State = ParseState.inited;
            }
            this.sock.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, out sockError, endRecv, null);
        }