java - Jetty EndPoint.flush(ByteBuffer b) 返回 false 时该怎么办?

标签 java jetty endpoint embedded-jetty jetty-8

我是第一次使用 Jetty 9 EndPoint。
但我对如何使用 EndPoint.flush(ByteBuffer) 方法返回码感到困惑。
我应该无限循环直到调用成功吗?

Javadoc 只是说

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).

顺便说一句,我正在调用的实例的类型是SslConnection$DecryptedEndPoint

任何见解都值得赞赏,因为我找不到任何文档来说明为什么不鼓励使用 SocketEndpoint 而首选 SelectChannelEndpoint。

<小时/>

有点离题,但无论如何; 令我惊讶的是,我在NetworkTrafficSelectChannelEndPoint中发现了这个:
使用操作|=代替&=(在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() 无法写入整个缓冲区,则返回 false。因此调用者知道它必须再次调用flush,直到所有数据都写入EndPoint。

查看 WriteFlusher.write() 和 WriteFlusher.completeWrite() 并阅读其中的 javadoc 以了解它的使用方式。

关于线路: 冲洗|=super.flush(b);//<<-- 不应该是&=

我想你是对的。 lushed 被初始化为 true,因此将始终为 true。我会仔细检查并可能修复它。

关于java - Jetty EndPoint.flush(ByteBuffer b) 返回 false 时该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17450537/

相关文章:

node.js - 使用 Node 和 Sails.JS 的端点别名?

java - 将资源放在jar文件中并暴露给网络

java - 使用java客户端在laravel中验证私有(private) channel 的问题

java - 列出由 Hudson 制作的所有构建的应用程序

annotations - 无法让Jetty扫描带注释的类

java - POST 中的 Jersey @HeaderParam null

node.js - Express中中间件功能的正确使用方法

java - 如何在Java声音中连续改变音高?

docker - 如何使用dockerized docker 更改默认 docker 端口

api - 如何找到我网站的所有 API?