[ 
https://issues.apache.org/jira/browse/HTTPCORE-368?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13852041#comment-13852041
 ] 

offbynull commented on HTTPCORE-368:
------------------------------------

Something I just noticed: A hasData() check could be added in to 
sendEncryptedData() to make sure that there's data available to be sent out. If 
there's nothing in the buffer, there's no point in acquiring and trying to send 
the buffer.

{{{
    private int sendEncryptedData() throws IOException {
        if (!this.outEncrypted.hasData()) {
            return 0;
        }

        // Acquire buffer
        ByteBuffer outEncryptedBuf = this.outEncrypted.acquire();

        // Perform operation
        outEncryptedBuf.flip();
        final int bytesWritten = this.session.channel().write(outEncryptedBuf);
        outEncryptedBuf.compact();

        // Release if empty
        if (outEncryptedBuf.position() == 0) {
            this.outEncrypted.release();
            outEncryptedBuf = null;
        }

        return bytesWritten;
    }
}}}

The only problem I see with this is that there may be a dependency somewhere up 
the call chain on the exceptions that write() throws back (e.g. if the 
connection's been closed / interrupted / whatever).

> Smarter use of buffers in SSLIOSession
> --------------------------------------
>
>                 Key: HTTPCORE-368
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-368
>             Project: HttpComponents HttpCore
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.3
>            Reporter: offbynull
>              Labels: patch
>             Fix For: 4.4
>
>         Attachments: SSLIOSession.patch, SSLIOSession3.patch, 
> SSLIOSession4.patch
>
>
> We're using the async client to load test our comet infrastructure. We're 
> frequently running in to OutOfMemoryErrors due to the ByteBuffers allocated 
> in SSLIOSession.
> The following is a quick-and-dirty patch to SSLIOSession that removes the 
> buffers when they aren't needed. Could we get this (or something similar to 
> this) added in to httpcore-nio?



--
This message was sent by Atlassian JIRA
(v6.1.4#6159)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to