/// <summary> /// 接收数据下一个请求数据 /// </summary> internal void ReceiveNext() { try { int receiveSize = receiveCount - receiveIndex; if (receiveSize == 0) { receiveIndex = receiveCount = HeaderEndIndex = 0; } else { HeaderEndIndex = receiveIndex; if (searchEnd()) { return; fixed(byte *bufferFixed = Buffer.Buffer) { byte *start = bufferFixed + Buffer.StartIndex; Memory.CopyNotNull(start + receiveIndex, start, receiveCount = receiveSize); } HeaderEndIndex -= receiveIndex; receiveIndex = 0; } //isHeader = 0; IsKeepAliveReceive = true; #if DOTNET2 SocketError socketError; IAsyncResult async = socket.BeginReceive(Buffer.Buffer, Buffer.StartIndex + receiveCount, ReceiveBufferSize - receiveCount, SocketFlags.None, out socketError, onReceiveAsyncCallback, socket); if (socketError == SocketError.Success) { if (!async.CompletedSynchronously) { KeepAliveReceiveTimeout.Push(httpSocket, socket); } return; } #else while (Interlocked.CompareExchange(ref httpSocket.ReceiveAsyncLock, 1, 0) != 0) { Thread.Sleep(0); } receiveAsyncEventArgs.SetBuffer(Buffer.StartIndex + receiveCount, ReceiveBufferSize - receiveCount); if (socket.ReceiveAsync(receiveAsyncEventArgs)) { KeepAliveReceiveTimeout.Push(httpSocket, socket); Interlocked.Exchange(ref httpSocket.ReceiveAsyncLock, 0); return; } Interlocked.Exchange(ref httpSocket.ReceiveAsyncLock, 0); if (onReceive()) { return; } #endif } catch (Exception error) { httpSocket.Server.RegisterServer.TcpServer.Log.Add(Log.LogType.Debug, error); } //if (isHeader == 0) httpSocket.HeaderError(); }
/// <summary> /// 接收数据下一个请求数据 /// </summary> internal void ReceiveNext() { try { int receiveSize = receiveCount - receiveIndex; if (receiveSize == 0) { receiveIndex = receiveCount = HeaderEndIndex = 0; } else { HeaderEndIndex = receiveIndex; if (searchEnd()) { return; fixed(byte *bufferFixed = Buffer.GetFixedBuffer()) { byte *start = bufferFixed + Buffer.StartIndex; AutoCSer.Memory.Common.CopyNotNull(start + receiveIndex, start, receiveCount = receiveSize); } HeaderEndIndex -= receiveIndex; receiveIndex = 0; } //isHeader = 0; IsKeepAliveReceive = true; #if DOTNET2 SocketError socketError; IAsyncResult async = socket.BeginReceive(Buffer.Buffer, Buffer.StartIndex + receiveCount, ReceiveBufferSize - receiveCount, SocketFlags.None, out socketError, onReceiveAsyncCallback, socket); if (socketError == SocketError.Success) { if (!async.CompletedSynchronously) { KeepAliveReceiveTimeout.Push(httpSocket, socket); } return; } #else httpSocket.ReceiveAsyncLock.EnterSleepFlag(); receiveAsyncEventArgs.SetBuffer(Buffer.StartIndex + receiveCount, ReceiveBufferSize - receiveCount); if (socket.ReceiveAsync(receiveAsyncEventArgs)) { httpSocket.ReceiveAsyncLock.SleepFlag = 0; KeepAliveReceiveTimeout.Push(httpSocket, socket); httpSocket.ReceiveAsyncLock.Exit(); return; } httpSocket.ReceiveAsyncLock.ExitSleepFlag(); if (onReceive()) { return; } #endif } catch (Exception error) { httpSocket.Server.RegisterServer.TcpServer.Log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer); } //if (isHeader == 0) httpSocket.HeaderError(); }