英文:
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
的实现中并没有实现。
我有以下几个问题:
- 为什么在
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!
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论