When using memory BIOs with OpenSSL, how can you find the 'needed size' for the input BIO?
<p>Here's some sample code which shows how I'm using OpenSSL:</p>

<pre><code>BIO *CreateMemoryBIO() {
    if (BIO *bio = BIO_new(BIO_s_mem())) {
        BIO_set_mem_eof_return(bio, -1);    
        return bio;
    }
    throw std::runtime_error("Could not create memory BIO");
}

m_readBIO = CreateMemoryBIO();
m_writeBIO = CreateMemoryBIO();
SSL_set_bio(m_ssl, m_readBIO, m_writeBIO);
</code></pre>

<p>Now, if I do an <code>SSL_Read</code>, and I get <code>SSL_ERROR_WANT_READ</code>, is there any way for me to find out how much it had tried to read internally (in other words, how much do I need to write with <code>BIO_write</code> to <code>m_readBIO</code> before <code>SSL_Read</code> would be satisfied?)</p>

<p>A good lower bound would work for me as well, my issue is that I need to report how much data to read to the layer above me, and it will not return control to me until it has read that much data (and I don't want to degenerate into 1-byte reads).</p>

<p>I'm aware that <code>SSL_Read</code> and <code>SSL_Write</code> may both alternately read &amp; write due to handshaking and such, but I'm interested in the 'current' read that is being done internally.</p>

<p>If it's not possible to do with the standard <code>BIO_s_mem</code>, I assume it could be done if I wrote my own BIO which 'remembered' the size of the last read request which failed, so any pointers to documentation on writing custom BIOs (which, to my knowledge, is supported by OpenSSL) would also be appreciated.</p>