gpt4 book ai didi

java - SelectionKey.interestOps(int ops) 的底层工作原理

转载 作者:行者123 更新时间:2023-12-02 12:17:39 25 4
gpt4 key购买 nike

据我了解,服务器套接字 channel 注册为监听接受,当接受时, channel 注册为读取,一旦读取,它就注册为写入,这是通过使用interestOps方法将相关键添加到SelectionKey的兴趣集中来完成的。

但是,当我们从键中删除一些interestOps时,例如 key.interestOps(key.interestOps() & ~SelectionKey.OP_READ);

这里到底发生了什么?这是否意味着服务器将不会监听属于此套接字的 channel 的任何传入请求,并且源 channel 将忽略服务器的此决定并可能继续向服务器发送数据?或者它会以某种方式告知 channel 来源这一决定。

用数据包交换的话说,上述操作实际上与服务器接收数据包相同,如果该数据包所属 channel 的interestKeys已“未设置”,则仅丢弃该数据包

最佳答案

However, when we remove some interestOps from a key for e.g key.interestOps(key.interestOps() & ~SelectionKey.OP_READ);

What actually happens here?

实际发生的情况是这样的:

public void interestOps(int interestOps)
{
this.interestOps = interestOps;
}

Does this mean that the server will just not listen for any incoming requests to channel belonging to this socket

这意味着如果数据通过套接字到达,Selector 不会触发任何 OP_READ 事件。这并不意味着不会收到数据。

and the source channel will be oblivious of this decision by the server and might keep on sending data to the server?

如果“源 channel ”指的是对等方,则无论如何都不建议这样做,除非接收缓冲区已填满。

Or will it somehow inform the channel source of this decision.

没有。

In packet switching parlance, is the above operation effectively the same as server receiving packets and just dropping the packet if the interestKeys for the channel this packet belong to have been "unset".

没有。

关于java - SelectionKey.interestOps(int ops) 的底层工作原理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46044633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com