/// <summary> /// 读操作 /// </summary> /// <param name="owinSocket"></param> /// <param name="buffer"></param> /// <param name="nread"></param> /// <param name="ex"></param> /// <param name="state"></param> private void OnReadCompleteCallback(OwinSocket owinSocket, byte[] buffer, int nread, Exception ex, object state) { if (nread < 1 || ex != null || buffer == null) { owinSocket.Dispose(); RequestDataFactory.Recover(_requestData); _requestData = null; return; } Buffer.BlockCopy(buffer, 0, _requestData, _requestDataOffset, nread); _requestDataOffset += nread; _requestDataSize += nread; if (_requestDataSize > 15) { int length = CommonUtil.GetBytesRealLength(_requestData, _requestDataSize, false); if (length > 0) { AddToProcessThread(length, owinSocket); return; } } if (_requestDataSize > 4000) { owinSocket.Dispose(); RequestDataFactory.Recover(_requestData); _requestData = null; return; } owinSocket.Read(new Action <OwinSocket, byte[], int, Exception, object>(OnReadCompleteCallback), null); }
/// <summary> /// 执行请求的入口 /// </summary> /// <param name="owinSocket"></param> public void Start(OwinSocket owinSocket) { if (_requestDataSize > 13) { int handleSize = CommonUtil.GetBytesRealLength(_requestData, _requestDataSize, false); if (handleSize > 0) { AddToProcessThread(handleSize, owinSocket); return; } } if (_requestDataSize > 4000) { owinSocket.Dispose(); RequestDataFactory.Recover(_requestData); _requestData = null; return; } owinSocket.Read(new Action <OwinSocket, byte[], int, Exception, object>(OnReadCompleteCallback), null); }