How to be notified when a SocketChannel is closed?

我的未来我决定 提交于 2019-12-04 03:10:45

If the SocketChannel is closed by you, you are closing it, so you can notify yourself any way you like.

If you want to be notified when the peer closes the connection,, OP_READ will fire and a read will return -1.

that's nasty. you could maybe use a byte level aop package like http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/ (with aop you can should be able to add a cutpoint on the close method that does your callback).

you could also create a package with the same name as the sun package and implement the inteface in there.

but i can't see a good, clean way to do this.

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