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

huangapple go评论86阅读模式
英文:

No CloseRead() / CloseWrite() implementation for tls.Conn

问题

我目前正在尝试将一个Go服务器从使用net.TCPConn切换到使用tls.Conn来进行API调用。我遇到的问题是,我的服务器依赖于net.TCPConn能够独立关闭读写连接的能力(通过net.TCPConn.CloseRead()net.TCPConn.CloseWrite()),而这个功能在net.Conn级别或者tls.Conn的实现中并没有实现。

我有以下几个问题:

  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!

答案1

得分: 1

我的服务器依赖于net.TCPConn的能力,可以独立关闭读取和写入连接。通常这样做是为了向对等方发出信号,表示不再发送数据,但仍然能够接收数据。这种能力是特定于TCP的,其中一方可以发送FIN信号表示传输结束,同时仍然接收数据。

由于这不是网络连接的通用功能,而是特定于TCP的,因此在通用的net.conn中提供此功能是没有意义的。类似地,TLS在一方关闭连接后也没有只读连接的概念。有关详细信息,请参阅boost ssl half close socket is possible?

英文:

> ... 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.

huangapple
  • 本文由 发表于 2022年2月22日 05:21:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/71213177.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定