/// <summary> /// Returns a buffer to be filled with binary data. /// </summary> public void GetBuffer(out ByteArraySegment data, out int size) { // If we are expected to read large message, we'll opt for zero- // copy, i.e. we'll ask caller to fill the data directly to the // message. Note that subsequent read(s) are non-blocking, thus // each single read reads at most SO_RCVBUF bytes at once not // depending on how large is the chunk returned from here. // As a consequence, large messages being received won't block // other engines running in the same I/O thread for excessive // amounts of time. if (m_toRead >= m_bufsize) { data = m_readPos.Clone(); size = m_toRead; return; } data = new ByteArraySegment(m_buf); size = m_bufsize; }