@@ -109,28 +109,6 @@ func socket(ctx context.Context, net string, family, sotype, proto int, ipv6only
109109 return nil , err
110110 }
111111
112- // This function makes a network file descriptor for the
113- // following applications:
114- //
115- // - An endpoint holder that opens a passive stream
116- // connection, known as a stream listener
117- //
118- // - An endpoint holder that opens a destination-unspecific
119- // datagram connection, known as a datagram listener
120- //
121- // - An endpoint holder that opens an active stream or a
122- // destination-specific datagram connection, known as a
123- // dialer
124- //
125- // - An endpoint holder that opens the other connection, such
126- // as talking to the protocol stack inside the kernel
127- //
128- // For stream and datagram listeners, they will only require
129- // named sockets, so we can assume that it's just a request
130- // from stream or datagram listeners when laddr is not nil but
131- // raddr is nil. Otherwise we assume it's just for dialers or
132- // the other connection holders.
133-
134112 if laddr != nil && raddr == nil {
135113 switch sotype {
136114 case syscall.SOCK_STREAM , syscall.SOCK_SEQPACKET :
@@ -177,4 +155,6 @@ func (fd *netFD) listenStream(laddr sockaddr, backlog int) error {
177155 fd.setAddr (fd.addrFunc ()(lsa), nil )
178156 return nil
179157}
180- ```
158+ ```
159+
160+ Go 的 listenTCP 一个函数就把 c 网络编程中 ` socket() ` ,` bind() ` ,` listen() ` 三步都完成了。大大减小了用户的心智负担。
0 commit comments