/// <summary> Sets up the DirectStreamLink with a certain behaviour. </summary> /// <param name="bufsize"> The size of the internal buffer to use. </param> /// <param name="blockOnFlush"> Specifies to block Flush until reader has read buffer empty. This is not suited for synching. </param> /// <param name="blockOnClose"> Specifies to block close of writer until reader has closed. Can be used for synching. </param> /// <param name="passWriteThrough"> A stream all written data is just passed to. For stream stacking. </param> public DirectStreamLink(int bufsize, bool blockOnFlush, bool blockOnClose, Stream passWriteThrough) { m_passWriteThrough = passWriteThrough; m_blockOnFlush = blockOnFlush; m_blockOnClose = blockOnClose; if (bufsize <= 0) { throw new ArgumentOutOfRangeException(nameof(bufsize), "The size of the buffer must be positive."); } m_buf = new byte[bufsize]; m_readerStream = new LinkedReaderStream(this); m_writerStream = new LinkedWriterStream(this); }
private void writerClosed() { lock (m_lock) { if (m_writerClosed) { return; } m_writerClosed = true; m_signalDataAvailable.Set(); // unblock potentially waiting reader m_writerStream = null; } flush(); // we close m_passWriteThrough before blocking, so if at end of chain (stacked DirectStreamLinks) // a blocked reader is waiting, it can proceed sooner. if (m_passWriteThrough != null) { m_passWriteThrough.Close(); } if (m_blockOnClose) // wait until reader has closed its stream before continuing. { while (!m_readerClosed) { lock (m_lock) { if (!m_readerClosed) { m_signalBufferAvailable.Reset(); } } m_signalBufferAvailable.Wait(); } } if (Interlocked.Decrement(ref m_autoDisposeCounter) == 0) { this.Dispose(); } }
private void writerClosed() { lock (m_lock) { if (m_writerClosed) return; m_writerClosed = true; m_signalDataAvailable.Set(); // unblock potentially waiting reader m_writerStream = null; } flush(); // we close m_passWriteThrough before blocking, so if at end of chain (stacked DirectStreamLinks) // a blocked reader is waiting, it can proceed sooner. if (m_passWriteThrough != null) { m_passWriteThrough.Close(); } if (m_blockOnClose) // wait until reader has closed its stream before continuing. { while (!m_readerClosed) { lock (m_lock) { if (!m_readerClosed) m_signalBufferAvailable.Reset(); } m_signalBufferAvailable.Wait(); } } if (Interlocked.Decrement(ref m_autoDisposeCounter) == 0) this.Dispose(); }
/// <summary> Sets up the DirectStreamLink with a certain behaviour. </summary> /// <param name="bufsize"> The size of the internal buffer to use. </param> /// <param name="blockOnFlush"> Specifies to block Flush until reader has read buffer empty. This is not suited for synching. </param> /// <param name="blockOnClose"> Specifies to block close of writer until reader has closed. Can be used for synching. </param> /// <param name="passWriteThrough"> A stream all written data is just passed to. For stream stacking. </param> public DirectStreamLink(int bufsize, bool blockOnFlush, bool blockOnClose, Stream passWriteThrough) { m_passWriteThrough = passWriteThrough; m_blockOnFlush = blockOnFlush; m_blockOnClose = blockOnClose; if (bufsize <= 0) throw new ArgumentOutOfRangeException("bufsize"); m_buf = new byte[bufsize]; m_readerStream = new LinkedReaderStream(this); m_writerStream = new LinkedWriterStream(this); }