From f82e74ca63f06e115c83115644c22e7bbe4892d4 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 7 Aug 2023 08:52:56 +0800 Subject: [PATCH] windows Signed-off-by: Adrian Cole --- internal/sysfs/sock_windows.go | 70 ++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/internal/sysfs/sock_windows.go b/internal/sysfs/sock_windows.go index e6cdff47a06..ed275e6290b 100644 --- a/internal/sysfs/sock_windows.go +++ b/internal/sysfs/sock_windows.go @@ -18,8 +18,6 @@ const ( MSG_PEEK = 0x2 // _FIONBIO is the flag to set the O_NONBLOCK flag on socket handles using ioctlsocket. _FIONBIO = 0x8004667e - // _WASWOULDBLOCK corresponds to syscall.EWOULDBLOCK in WinSock. - _WASWOULDBLOCK = 10035 ) var ( @@ -27,12 +25,8 @@ var ( modws2_32 = syscall.NewLazyDLL("ws2_32.dll") // procrecvfrom exposes recvfrom from WinSock. procrecvfrom = modws2_32.NewProc("recvfrom") - // procaccept exposes accept from WinSock. - procaccept = modws2_32.NewProc("accept") // procioctlsocket exposes ioctlsocket from WinSock. procioctlsocket = modws2_32.NewProc("ioctlsocket") - // procselect exposes select from WinSock. - procselect = modws2_32.NewProc("select") ) // recvfrom exposes the underlying syscall in Windows. @@ -142,12 +136,25 @@ func (f *winTcpListenerFile) Accept() (socketapi.TCPConn, sys.Errno) { } } -// IsNonblock implements File.IsNonblock +// Close implements the same method as documented on sys.File +func (f *winTcpListenerFile) Close() sys.Errno { + if !f.closed { + return sys.UnwrapOSError(f.tl.Close()) + } + return 0 +} + +// Addr is exposed for testing. +func (f *winTcpListenerFile) Addr() *net.TCPAddr { + return f.tl.Addr().(*net.TCPAddr) +} + +// IsNonblock implements the same method as documented on fsapi.File func (f *winTcpListenerFile) IsNonblock() bool { return f.nonblock } -// SetNonblock implements the same method as documented on sys.File +// SetNonblock implements the same method as documented on fsapi.File func (f *winTcpListenerFile) SetNonblock(enabled bool) sys.Errno { f.nonblock = enabled _, errno := syscallConnControl(f.tl, func(fd uintptr) (int, sys.Errno) { @@ -156,17 +163,9 @@ func (f *winTcpListenerFile) SetNonblock(enabled bool) sys.Errno { return errno } -// Close implements the same method as documented on sys.File -func (f *winTcpListenerFile) Close() sys.Errno { - if !f.closed { - return sys.UnwrapOSError(f.tl.Close()) - } - return 0 -} - -// Addr is exposed for testing. -func (f *winTcpListenerFile) Addr() *net.TCPAddr { - return f.tl.Addr().(*net.TCPAddr) +// Poll implements the same method as documented on fsapi.File +func (f *winTcpListenerFile) Poll(fsapi.Pflag, int32) (ready bool, errno sys.Errno) { + return false, sys.ENOSYS } var _ socketapi.TCPConn = (*winTcpConnFile)(nil) @@ -190,20 +189,6 @@ func newTcpConn(tc *net.TCPConn) socketapi.TCPConn { return &winTcpConnFile{tc: tc} } -// SetNonblock implements the same method as documented on sys.File -func (f *winTcpConnFile) SetNonblock(enabled bool) (errno sys.Errno) { - f.nonblock = true - _, errno = syscallConnControl(f.tc, func(fd uintptr) (int, sys.Errno) { - return 0, sys.UnwrapOSError(setNonblockSocket(syscall.Handle(fd), enabled)) - }) - return -} - -// IsNonblock implements File.IsNonblock -func (f *winTcpConnFile) IsNonblock() bool { - return f.nonblock -} - // Read implements the same method as documented on sys.File func (f *winTcpConnFile) Read(buf []byte) (n int, errno sys.Errno) { if len(buf) == 0 { @@ -279,3 +264,22 @@ func (f *winTcpConnFile) close() sys.Errno { f.closed = true return f.Shutdown(syscall.SHUT_RDWR) } + +// IsNonblock implements the same method as documented on fsapi.File +func (f *winTcpConnFile) IsNonblock() bool { + return f.nonblock +} + +// SetNonblock implements the same method as documented on fsapi.File +func (f *winTcpConnFile) SetNonblock(enabled bool) (errno sys.Errno) { + f.nonblock = true + _, errno = syscallConnControl(f.tc, func(fd uintptr) (int, sys.Errno) { + return 0, sys.UnwrapOSError(setNonblockSocket(syscall.Handle(fd), enabled)) + }) + return +} + +// Poll implements the same method as documented on fsapi.File +func (f *winTcpConnFile) Poll(fsapi.Pflag, int32) (ready bool, errno sys.Errno) { + return false, sys.ENOSYS +}