tls.Conn 没有 CloseRead() / CloseWrite() 实现
我目前正在尝试将 Go 服务器从使用 net.TCPConn
切换为使用 tls.Conn
进行 API 调用。我遇到的问题是我的服务器依赖 net.TCPConn
独立关闭读写连接的能力(通过 net.TCPConn.CloseRead()
和net.TCPConn.CloseWrite()
),该功能未在 net.Conn
级别或 tls.Conn
实现中实现。*
* 我知道tls.Conn
确实有 CloseWrite()
的实现,但在幕后此方法仅调用 SetWriteDeadline()
并且不会关闭文件描述符,这是我需要的功能。
我的问题如下:
- 是否有特定的设计原因导致在
net.Conn
中没有实现CloseRead()
和CloseWrite()
?看起来像net.Conn
的实现具有这些方法,它们的定义几乎相同。 - 为什么 tls.Conn 中没有实现这些方法来关闭文件描述符?
预先感谢您的回复!
I am currently trying to switch a Go server from using a net.TCPConn
to using a tls.Conn
for its API calls. The problem I am running into is that my server relies on net.TCPConn
's ability to close the read and write connection independently (via net.TCPConn.CloseRead()
and net.TCPConn.CloseWrite()
), a feature which is not implemented at the net.Conn
level or in tls.Conn
implementation.*
* I know that tls.Conn
does have an implementation of CloseWrite()
, but under the hood this method only calls SetWriteDeadline()
and doesn't close the file descriptor, which is the functionality that I need.
My questions are as follows:
- Is there a specific design reason for not having an implementation for
CloseRead()
andCloseWrite()
innet.Conn
? It looks like the implementations ofnet.Conn
that have these methods define them almost identically. - Why isn't there an implementation of these methods in
tls.Conn
which closes the file descriptors?
Thank you in advance for your response!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
依赖于此通常是为了向对等方发出信号,表明在仍然能够接收数据的同时不会再发送任何数据。此功能是 TCP 特有的,其中一方可以在仍然接收数据的同时发送 FIN 来表示传输结束。
由于它不是网络连接的通用功能,而是特定于 TCP,因此在通用 net.conn 中为此提供接口是没有意义的。类似的 TLS 也没有单侧关闭后只读连接的概念 - 请参阅 boost ssl half close socket 是可能的吗? 了解详细信息。
Relying on this is usually done to signal to the peer that no more data will be sent while still being able to receive data. This ability is specific to TCP, where one side can send a FIN to signal end of transmission while still receiving data.
Since it is not a generic feature of network connections but specific to TCP it makes no sense to provide an interface for this in the generic net.conn. Similar TLS also does not have the concept of a read-only connectivity after a one-side shutdown - see boost ssl half close socket is possible? for details.