简体   繁体   English

SocketChannel.close()是否也会关闭套接字?

[英]Does SocketChannel.close() close the socket also?

I have a server program that needs to close any connections that remain when the server is shutting down. 我有一个服务器程序,需要关闭服务器关闭时剩余的所有连接。 I know I need to call SocketChannel.close() . 我知道我需要调用SocketChannel.close() My question is if I also need to close the Socket associated with the SocketChannel or if SocketChannel.close() does that automatically. 我的问题是我是否还需要关闭与SocketChannel关联的Socket,或者SocketChannel.close()是否自动执行此操作。

Of course it closes the socket. 当然,它会关闭插座。 What else would it be for? 还有什么呢? The only exception is when the channel is registered with a Selector, when the actual close is deferred to the next select operation. 唯一的例外是当通道向选择器注册时,实际关闭时间推迟到下一个选择操作时。

SocketChannel.close() should close the Socket. SocketChannel.close()应该关闭Socket。 However, there have been some bugs around this issue (should have been solved a long time ago). 但是,此问题周围存在一些错误(应该早已解决)。 http://bugs.sun.com/view_bug.do?bug_id=4960962 . http://bugs.sun.com/view_bug.do?bug_id=4960962 Another situation that can cause problems: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6179351 可能导致问题的另一种情况: http : //bugs.sun.com/bugdatabase/view_bug.do?bug_id=6179351

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM