我第一次使用 Jetty 9 EndPoint。
但我不知道如何使用EndPoint.flush(ByteBuffer)方法返回码。
我应该无限循环直到调用成功吗?
Javadoc 只是说
返回: True IFF 所有缓冲区都已被消耗,并且端点已将数据刷新到其目的地(即没有缓冲任何数据)。
顺便说一句,我正在调用的实例是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;
}