You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func sysSocket(family, sotype, proto int) (int, error) {
**//创建socket 时就设置了非阻塞模式**
s, err := socketFunc(family, sotype|syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC, proto)
// On Linux the SOCK_NONBLOCK and SOCK_CLOEXEC flags were
// introduced in 2.6.27 kernel and on FreeBSD both flags were
// introduced in 10 kernel. If we get an EINVAL error on Linux
// or EPROTONOSUPPORT error on FreeBSD, fall back to using
// socket without them.
switch err {
case nil:
return s, nil
default:
return -1, os.NewSyscallError("socket", err)
case syscall.EPROTONOSUPPORT, syscall.EINVAL:
}
// Network file descriptor.
type netFD struct {
pfd poll.FD
// immutable until Close
family int
sotype int
isConnected bool
net string
laddr Addr
raddr Addr
}
poll.FD 结构体
C:\Go\src\internal\poll\fd_unix.go
// FD is a file descriptor. The net and os packages use this type as a
// field of a larger type representing a network connection or OS file.
type FD struct {
// Lock sysfd and serialize access to Read and Write methods.
fdmu fdMutex
// System file descriptor. Immutable until Close.
Sysfd int
// I/O poller.
pd pollDesc
// Writev cache.
iovecs *[]syscall.Iovec
// Semaphore signaled when file is closed.
csema uint32
// Whether this is a streaming descriptor, as opposed to a
// packet-based descriptor like a UDP socket. Immutable.
IsStream bool
// Whether a zero byte read indicates EOF. This is false for a
// message based socket connection.
ZeroReadIsEOF bool
// Whether this is a file rather than a network socket.
isFile bool
// Whether this file has been set to blocking mode.
isBlocking bool
}
The text was updated successfully, but these errors were encountered:
主要看下sysfd--> netFD 如何加入netpoll 过程。
fd netFD-->pfd poll.FD 带有Sysfd--> pd pollDesc
fd.pfd.pd.Init()
C:\Go\src\net\tcpsock_posix.go
DialContext-->dialSerial--> dialTCP -->doDialTCP
go tcp 默认就设置nodelay
C:\Go\src\net\ipsock_posix.go
C:\Go\src\net\sock_posix.go
C:\Go\src\net\sock_cloexec.go
socketFunc func(int, int, int) (int, error) = syscall.Socket
C:\Go\src\net\fd_unix.go
C:\Go\src\runtime\netpoll.go
C:\Go\src\runtime\netpoll_epoll.go
作为TCPConn, Accept() , netFD.Accept()--> poll.FD.Accept--> accept( poll.FD.Sysfd)
C:\Go\src\net\fd_unix.go :
C:\Go\src\internal\poll\fd_unix.go : pfd.Accept()
// Accept wraps the accept network call.
poll.FD 结构体
C:\Go\src\internal\poll\fd_unix.go
The text was updated successfully, but these errors were encountered: