/// <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); }
private static void WriteCallBack(OwinSocket socket, int num, Exception ex, object obj) { RequestData requestData = obj as RequestData; if (requestData == null) { socket.Dispose(); return; } if (!requestData.IsKeepAlive() || ex != null) { requestData.SaveToPoll(); socket.Dispose(); return; } byte[] preLoadedBody = requestData._preLoadedBody; requestData.SaveToPoll(); OwinHttpWorkerManage.Start(socket, preLoadedBody); }
/// <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); }
/// <summary> /// 写操作完毕的回调事件 /// </summary> /// <param name="owinSocket"></param> /// <param name="status"></param> /// <param name="ex"></param> /// <param name="state"></param> private void OnWriteCompleteToClose(OwinSocket owinSocket, int status, Exception ex, object state) { owinSocket.Dispose(); }