문제

i'm using Jetty 9 EndPoint for the first time.
But i'm stuck as to how to use the EndPoint.flush(ByteBuffer) method returncode.
Should i loop indefinitly until the call succeeds ?

Javadoc just says

Returns: True IFF all the buffers have been consumed and the endpoint has flushed the data to its destination (ie is not buffering any data).

By the way, the instance i'm calling on is of type SslConnection$DecryptedEndPoint

Any insight is appreciated, since i can't find any documentation as to why SocketEndpoint is discouraged and SelectChannelEndpoint is preferred.


A bit offtopic but anyway; To my surprise i found this in NetworkTrafficSelectChannelEndPoint:
the operation |= is used instead of &= (found in jetty-all-9.0.3.v20130506-sources.jar)

@Override
public boolean flush(ByteBuffer... buffers) throws IOException
{
    boolean flushed=true;
    for (ByteBuffer b : buffers)
    {
        if (b.hasRemaining())
        {
            int position = b.position();
            flushed|=super.flush(b); // <<-- shouldn't it be &=
            int l=b.position()-position;
            notifyOutgoing(b, position, l);
            if (!flushed)
                break;
        }
    }
    return flushed;
}
도움이 되었습니까?

해결책

EndPoint.flush() returns false if it couldn't write the whole buffers. Thus the caller knows it has to call flush again until all data has been written to the EndPoint.

Have a look at WriteFlusher.write() and WriteFlusher.completeWrite() and read the javadocs there to get a feel of how it is used.

Regarding the line: flushed|=super.flush(b); // <<-- shouldn't it be &=

I guess you're right. flushed is initialized to true and therefore will always be true that way. I will doublecheck and possibly fix it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top