@
est 我当然仔细看过了。这跟OOP没有关系,只要writeRecord, readRecord这些方法可见,可以用embedded的tls.Conn
type Conn struct {
tls.Conn
}
func (c *Conn) Heartbeat(...) {...}
这样的效果和继承是一样的。根本原因是作者需要用到tls.Conn没暴露的方法来做坏事,正常的用途根本不需要tls.Conn的私有方法。所以标准库没有暴露出WriteRecord, ReadRecord。
net.TCPConn如果直接暴露fd,又不知道多少人会踩坑来骂了。链接里都有人说了
"The reason why you cannot access it is the networking package requires
that it controls the blocking mode of any fds it owns. If you were
able to get access to sysfd, you could change the blocking mode
yourself which would cause havock with the poller. "
它本来就不想让你用,非要用,不方便也没什么好说的。
还有种做法是直接调用C api拿到fd,再包装成net.Conn