diff options
| author | qmuntal <quimmuntal@gmail.com> | 2024-01-19 14:14:17 +0100 |
|---|---|---|
| committer | Quim Muntal <quimmuntal@gmail.com> | 2024-01-23 15:36:19 +0000 |
| commit | d0dc93c8e1a5be4e0a44b7f8ecb0cb1417de50ce (patch) | |
| tree | 1c6367b1b8d3d6e91475f2f9911ca52d79e8b46b /src/runtime | |
| parent | 704401ffa06c60e059c9e6e4048045b4ff42530a (diff) | |
| download | go-d0dc93c8e1a5be4e0a44b7f8ecb0cb1417de50ce.tar.xz | |
runtime,internal/poll: move websocket handling out of the runtime on Windows
On Windows, the netpoll is currently coupled with the websocket usage
in the internal/poll package.
This CL moves the websocket handling out of the runtime and puts it into
the internal/poll package, which already contains most of the async I/O
logic for websockets.
This is a good refactor per se, as the Go runtime shouldn't know about
websockets. In addition, it will make it easier (in a future CL) to only
load ws2_32.dll when the Go program actually uses websockets.
Change-Id: Ic820872cf9bdbbf092505ed7f7504edb6687735e
Reviewed-on: https://go-review.googlesource.com/c/go/+/556936
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/netpoll_windows.go | 29 | ||||
| -rw-r--r-- | src/runtime/os_windows.go | 11 |
2 files changed, 8 insertions, 32 deletions
diff --git a/src/runtime/netpoll_windows.go b/src/runtime/netpoll_windows.go index 484a9e85b2..59377bc588 100644 --- a/src/runtime/netpoll_windows.go +++ b/src/runtime/netpoll_windows.go @@ -19,10 +19,8 @@ type net_op struct { // used by windows o overlapped // used by netpoll - pd *pollDesc - mode int32 - errno int32 - qty uint32 + pd *pollDesc + mode int32 } type overlappedEntry struct { @@ -86,7 +84,7 @@ func netpollBreak() { // delay > 0: block for up to that many nanoseconds func netpoll(delay int64) (gList, int32) { var entries [64]overlappedEntry - var wait, qty, flags, n, i uint32 + var wait, n, i uint32 var errno int32 var op *net_op var toRun gList @@ -131,12 +129,12 @@ func netpoll(delay int64) (gList, int32) { for i = 0; i < n; i++ { op = entries[i].op if op != nil && op.pd == entries[i].key { - errno = 0 - qty = 0 - if stdcall5(_WSAGetOverlappedResult, op.pd.fd, uintptr(unsafe.Pointer(op)), uintptr(unsafe.Pointer(&qty)), 0, uintptr(unsafe.Pointer(&flags))) == 0 { - errno = int32(getlasterror()) + mode := op.mode + if mode != 'r' && mode != 'w' { + println("runtime: GetQueuedCompletionStatusEx returned net_op with invalid mode=", mode) + throw("runtime: netpoll failed") } - delta += handlecompletion(&toRun, op, errno, qty) + delta += netpollready(&toRun, op.pd, mode) } else { netpollWakeSig.Store(0) if delay == 0 { @@ -148,14 +146,3 @@ func netpoll(delay int64) (gList, int32) { } return toRun, delta } - -func handlecompletion(toRun *gList, op *net_op, errno int32, qty uint32) int32 { - mode := op.mode - if mode != 'r' && mode != 'w' { - println("runtime: GetQueuedCompletionStatusEx returned invalid mode=", mode) - throw("runtime: netpoll failed") - } - op.errno = errno - op.qty = qty - return netpollready(toRun, op.pd, mode) -} diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go index cd0a3c260e..7e9bbd04f2 100644 --- a/src/runtime/os_windows.go +++ b/src/runtime/os_windows.go @@ -139,7 +139,6 @@ var ( // These are from non-kernel32.dll, so we prefer to LoadLibraryEx them. _timeBeginPeriod, _timeEndPeriod, - _WSAGetOverlappedResult, _ stdFunction ) @@ -148,7 +147,6 @@ var ( ntdlldll = [...]uint16{'n', 't', 'd', 'l', 'l', '.', 'd', 'l', 'l', 0} powrprofdll = [...]uint16{'p', 'o', 'w', 'r', 'p', 'r', 'o', 'f', '.', 'd', 'l', 'l', 0} winmmdll = [...]uint16{'w', 'i', 'n', 'm', 'm', '.', 'd', 'l', 'l', 0} - ws2_32dll = [...]uint16{'w', 's', '2', '_', '3', '2', '.', 'd', 'l', 'l', 0} ) // Function to be called by windows CreateThread @@ -256,15 +254,6 @@ func loadOptionalSyscalls() { } _RtlGetCurrentPeb = windowsFindfunc(n32, []byte("RtlGetCurrentPeb\000")) _RtlGetNtVersionNumbers = windowsFindfunc(n32, []byte("RtlGetNtVersionNumbers\000")) - - ws232 := windowsLoadSystemLib(ws2_32dll[:]) - if ws232 == 0 { - throw("ws2_32.dll not found") - } - _WSAGetOverlappedResult = windowsFindfunc(ws232, []byte("WSAGetOverlappedResult\000")) - if _WSAGetOverlappedResult == nil { - throw("WSAGetOverlappedResult not found") - } } func monitorSuspendResume() { |
