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.ReciveInternal(); CompleteRead(); } }
public void Flush(bool moreData) { if (_remainingSpaceInOutputSegment == 0) { _socket.CommitSend(); } else if (_remainingSpaceInOutputSegment == _outputSegmentTotalLength) { return; } else { unsafe { _currentOutputSegment.SegmentPointer->Length = _outputSegmentTotalLength - _remainingSpaceInOutputSegment; } _socket.SendInternal(_currentOutputSegment, RIO_SEND_FLAGS.NONE); if (moreData) { _currentOutputSegment = _socket.SendBufferPool.GetBuffer(); _outputSegmentTotalLength = _currentOutputSegment.TotalLength; _remainingSpaceInOutputSegment = _outputSegmentTotalLength; } else { _remainingSpaceInOutputSegment = 0; _outputSegmentTotalLength = 0; } } }
public void Flush(bool moreData) { if (_remainingSpaceInOutputSegment == 0) _socket.CommitSend(); else if (_remainingSpaceInOutputSegment == _outputSegmentTotalLength) return; else { unsafe { _currentOutputSegment.SegmentPointer->Length = _outputSegmentTotalLength - _remainingSpaceInOutputSegment; } _socket.SendInternal(_currentOutputSegment, RIO_SEND_FLAGS.NONE); if (moreData) { _currentOutputSegment = _socket.SendBufferPool.GetBuffer(); _outputSegmentTotalLength = _currentOutputSegment.TotalLength; _remainingSpaceInOutputSegment = _outputSegmentTotalLength; } else { _remainingSpaceInOutputSegment = 0; _outputSegmentTotalLength = 0; } } }
public RioBufferSegment GetResult() { var res = _currentValue; _currentValue = null; return(res); }
internal unsafe void SendInternal(RioBufferSegment segment, RIO_SEND_FLAGS flags) { if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index)) { WinSock.ThrowLastWSAError(); } }
private void CompleteRead() { var toCopy = _currentContentLength - _bytesReadInCurrentSegment; if (toCopy > _readCount) { toCopy = _readCount; } unsafe { fixed(byte *p = &_readBuffer[_readoffset]) System.Buffer.MemoryCopy(_currentInputSegment.RawPointer + _bytesReadInCurrentSegment, p, _readCount, toCopy); } _bytesReadInCurrentSegment += toCopy; if (_currentContentLength == _bytesReadInCurrentSegment) { _currentInputSegment.Dispose(); _currentInputSegment = null; } _readtcs.SetResult(toCopy); }
public void WritePreAllocated(RioBufferSegment Segment) { unsafe { if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index)) WinSock.ThrowLastWSAError(); } }
public RioStream(RioConnectionOrientedSocket socket) { _socket = socket; _currentInputSegment = null; _currentOutputSegment = _socket.SendBufferPool.GetBuffer(); _getNewSegmentDelegate = GetNewSegment; socket.OnIncommingSegment = s => _incommingSegments.Set(s); socket.ReciveInternal(); }
public void Dispose() { _currentValue?.Dispose(); _currentValue = null; if (_continuation != null) { _continuation(); } }
public void WritePreAllocated(RioBufferSegment Segment) { unsafe { if (!RioStatic.Send(_requestQueue, Segment.SegmentPointer, 1, RIO_SEND_FLAGS.DEFER, Segment.Index)) { WinSock.ThrowLastWSAError(); } } }
public RioFixedBufferPool(int segmentCount, int segmentLength) { AllSegments = new RioBufferSegment[segmentCount]; TotalLength = segmentCount * segmentLength; BufferPointer = Marshal.AllocHGlobal(TotalLength); _segmentpointer = Marshal.AllocHGlobal(Marshal.SizeOf<RIO_BUFSEGMENT>() * segmentCount); for (int i = 0; i < segmentCount; i++) { var b = new RioBufferSegment(this, BufferPointer, _segmentpointer, i, segmentLength); AllSegments[i] = b; _availableSegments.Enqueue(b); } }
public RioFixedBufferPool(int segmentCount, int segmentLength) { AllSegments = new RioBufferSegment[segmentCount]; TotalLength = segmentCount * segmentLength; BufferPointer = Marshal.AllocHGlobal(TotalLength); _segmentpointer = Marshal.AllocHGlobal(Marshal.SizeOf <RIO_BUFSEGMENT>() * segmentCount); for (int i = 0; i < segmentCount; i++) { var b = new RioBufferSegment(this, BufferPointer, _segmentpointer, i, segmentLength); AllSegments[i] = b; _availableSegments.Enqueue(b); } }
public void Set(RioBufferSegment item) { bool taken = false; _spinLock.Enter(ref taken); //if (!taken) // throw new ArgumentException("fuu"); //if (_currentValue != null) // throw new ArgumentException("fuu"); _currentValue = item; _spinLock.Exit(); if (_continuation != null) ThreadPool.QueueUserWorkItem(_continuationWrapperDelegate, null); }
public void Set(RioBufferSegment item) { bool taken = false; _spinLock.Enter(ref taken); //if (!taken) // throw new ArgumentException("fuu"); //if (_currentValue != null) // throw new ArgumentException("fuu"); _currentValue = item; _spinLock.Exit(); if (_continuation != null) { ThreadPool.QueueUserWorkItem(_continuationWrapperDelegate, null); } }
internal unsafe void SendInternal(RioBufferSegment segment, RIO_SEND_FLAGS flags) { if (!RioStatic.Send(_requestQueue, segment.SegmentPointer, 1, flags, segment.Index)) WinSock.ThrowLastWSAError(); }
public void ReleaseBuffer(RioBufferSegment bufferIndex) { _availableSegments.Enqueue(bufferIndex); }
public bool TryGetBuffer(out RioBufferSegment buf) { return(_availableSegments.TryDequeue(out buf)); }
private void CompleteRead() { var toCopy = _currentContentLength - _bytesReadInCurrentSegment; if (toCopy > _readCount) toCopy = _readCount; unsafe { fixed (byte* p = &_readBuffer[_readoffset]) System.Buffer.MemoryCopy(_currentInputSegment.RawPointer + _bytesReadInCurrentSegment, p, _readCount, toCopy); } _bytesReadInCurrentSegment += toCopy; if (_currentContentLength == _bytesReadInCurrentSegment) { _currentInputSegment.Dispose(); _currentInputSegment = null; } _readtcs.SetResult(toCopy); }
public RioBufferSegment GetResult() { var res = _currentValue; _currentValue = null; return res; }
public void Dispose() { _currentValue?.Dispose(); _currentValue = null; if (_continuation != null) _continuation(); }
public bool TryGetBuffer(out RioBufferSegment buf) { return _availableSegments.TryDequeue(out buf); }