tls.Conn 没有 CloseRead() / CloseWrite() 实现

发布于 2025-01-09 06:55:00 字数 653 浏览 0 评论 0原文

我目前正在尝试将 Go 服务器从使用 net.TCPConn 切换为使用 tls.Conn 进行 API 调用。我遇到的问题是我的服务器依赖 net.TCPConn 独立关闭读写连接的能力(通过 net.TCPConn.CloseRead()net.TCPConn.CloseWrite()),该功能未在 net.Conn 级别或 tls.Conn 实现中实现。*

* 我知道tls.Conn 确实有 CloseWrite() 的实现,但在幕后此方法仅调用 SetWriteDeadline() 并且不会关闭文件描述符,这是我需要的功能。

我的问题如下:

  1. 是否有特定的设计原因导致在 net.Conn 中没有实现 CloseRead()CloseWrite() ?看起来像 net.Conn 的实现具有这些方法,它们的定义几乎相同。
  2. 为什么 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:

  1. Is there a specific design reason for not having an implementation for CloseRead() and CloseWrite() in net.Conn? It looks like the implementations of net.Conn that have these methods define them almost identically.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笙痞 2025-01-16 06:55:00

...我的服务器依赖net.TCPConn独立关闭读写连接的能力...

依赖于此通常是为了向对等方发出信号,表明在仍然能够接收数据的同时不会再发送任何数据。此功能是 TCP 特有的,其中一方可以在仍然接收数据的同时发送 FIN 来表示传输结束。

由于它不是网络连接的通用功能,而是特定于 TCP,因此在通用 net.conn 中为此提供接口是没有意义的。类似的 TLS 也没有单侧关闭后只读连接的概念 - 请参阅 boost ssl half close socket 是可能的吗? 了解详细信息。

... my server relies on net.TCPConn's ability to close the read and write connection independently ...

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文