void Flush(bool disposing) { if (_remainingSpaceInOutputSegment == 0) { _socket.Flush(); } else if (_remainingSpaceInOutputSegment == _outputSegmentTotalLength) { if (disposing) { _currentOutputSegment.Dispose(); } } else { unsafe { _currentOutputSegment.SegmentPointer->Length = _outputSegmentTotalLength - _remainingSpaceInOutputSegment; } _socket.Send(_currentOutputSegment, RIO_SEND_FLAGS.NONE); _currentOutputSegment.Dispose(); if (disposing) { _remainingSpaceInOutputSegment = 0; _outputSegmentTotalLength = 0; } else { _currentOutputSegment = _socket.SendBufferPool.GetBuffer(); _outputSegmentTotalLength = _currentOutputSegment.TotalLength; _remainingSpaceInOutputSegment = _outputSegmentTotalLength; } } }
private void CompleteRead() { var toCopy = _currentContentLength - _bytesReadInCurrentSegment; if (toCopy > _readCount) { toCopy = _readCount; } unsafe { fixed(byte *p = &_readBuffer[_readoffset]) Buffer.MemoryCopy(_currentInputSegment.RawPointer + _bytesReadInCurrentSegment, p, _readCount, toCopy); } _bytesReadInCurrentSegment += toCopy; if (_currentContentLength == _bytesReadInCurrentSegment) { _currentInputSegment.Dispose(); _currentInputSegment = null; } _readtcs.SetResult(toCopy); }
private void GetNewSegment() { _currentInputSegment = _incommingSegments.GetResult(); if (_currentInputSegment == null) { _readtcs.SetResult(0); return; } _bytesReadInCurrentSegment = 0; _currentContentLength = _currentInputSegment.CurrentContentLength; if (_currentContentLength == 0) { _currentInputSegment.Dispose(); _currentInputSegment = null; _readtcs.SetResult(0); return; } else { _socket.BeginReceive(); CompleteRead(); } }
protected override void Dispose(bool disposing) { Flush(false); _nextInputSegment?.Dispose(); _currentInputSegment?.Dispose(); }
public void Dispose() { _currentValue?.Dispose(); _currentValue = null; if (_continuation != null) { _continuation(); } }
protected override void Dispose(bool disposing) { if (this.disposing) { return; } this.disposing = true; Flush(true); _nextInputSegment?.Dispose(); _currentInputSegment?.Dispose(); }
protected override void Dispose(bool disposing) { Flush(false); if (_currentInputSegment != null) { _currentInputSegment.Dispose(); } _currentOutputSegment.Dispose(); _incommingSegments.Dispose(); }
int GetNewSegment() { if (_nextInputSegment.CurrentContentLength == 0) { _nextInputSegment.Dispose(); _currentInputSegment.Dispose(); return(0); } else { _bytesReadInCurrentSegment = 0; _nextInputSegment = _socket.BeginReceive(Interlocked.Exchange(ref _currentInputSegment, _nextInputSegment)); return(CompleteRead()); } }
private int GetNewSegment() { var tmp = _currentInputSegment; _nextInputSegment.GetResult(); _currentInputSegment = _nextInputSegment; _bytesReadInCurrentSegment = 0; _currentContentLength = _currentInputSegment.CurrentContentLength; if (_currentContentLength == 0) { _currentInputSegment.Dispose(); tmp.Dispose(); return 0; } else { _nextInputSegment = tmp; _socket.BeginReceive(_nextInputSegment); return CompleteRead(); } }
public void Dispose() { _nextInputSegment.Dispose(); _currentInputSegment.Dispose(); }