Add key to a selected keys set

那年仲夏 提交于 2019-12-02 10:49:41

You can't. From the Javadoc:

Keys may not be added directly to the selected-key set.

You can only remove keys from it.

But you don't need any of this. If you want to write, just write, and if and only if the write returns zero, register the channel for OP_WRITE and return to the select loop. When and if the channel becomes writable, it will be added to the selected keys set automatically. You don't need to wait for OP_WRITE to do the initial write.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!