我第一次使用Jetty 9 EndPoint
但我不知道如何使用 EndPoint.flush(ByteBuffer)方法返回码。
我应该无限循环直到通话成功吗?
Javadoc只是说
返回: 真的IFF已经消耗了所有缓冲区,并且端点已将数据刷新到其目的地(即不缓冲任何数据)。
顺便说一句,我正在调用的实例是 SslConnection $ DecryptedEndPoint
类型非常感谢任何见解,因为我找不到任何关于为什么不鼓励使用SocketEndpoint并且首选SelectChannelEndpoint的文档。
有点offtopic但无论如何;
令我惊讶的是,我在 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;
}
答案 0 :(得分:1)
如果EndPoint.flush()无法写入整个缓冲区,则返回false。因此调用者知道它必须再次调用flush,直到所有数据都写入EndPoint。
查看WriteFlusher.write()和WriteFlusher.completeWrite()并阅读那里的javadoc以了解它是如何被使用的。
关于这一行: 冲洗| = super.flush(B); //&lt;&lt; - 不应该是&amp; =
我猜你是对的。刷新初始化为true,因此将始终如此。我会仔细检查并修复它。