diff options
| author | qmuntal <quimmuntal@gmail.com> | 2024-01-19 16:27:22 +0100 |
|---|---|---|
| committer | Quim Muntal <quimmuntal@gmail.com> | 2024-01-23 18:57:32 +0000 |
| commit | 9368ced7555d9320e93e83e18a67faa9af1226b9 (patch) | |
| tree | 3cbe7603c853da8e678ea9b30ef1adb1f80c7545 /src/internal | |
| parent | 4085a4893c427a2138e28fe4f16a646e7f571adb (diff) | |
| download | go-9368ced7555d9320e93e83e18a67faa9af1226b9.tar.xz | |
net,internal/poll: load ws2_32.dll only when net is imported
On Windows, ws2_32.dll is loaded and WSA initialized even if websockets
are not used.
This CL delays loading of ws2_32.dll and starting WSA until net is
initialized.
Change-Id: I07ea8241d79709cd4e80d29ba0d792c7444bbfe9
Reviewed-on: https://go-review.googlesource.com/c/go/+/557015
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/internal')
| -rw-r--r-- | src/internal/poll/fd_windows.go | 7 | ||||
| -rw-r--r-- | src/internal/poll/fd_windows_test.go | 2 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go index fe23d4b3d7..b08ca615c6 100644 --- a/src/internal/poll/fd_windows.go +++ b/src/internal/poll/fd_windows.go @@ -53,14 +53,17 @@ func checkSetFileCompletionNotificationModes() { useSetFileCompletionNotificationModes = true } -func init() { +// InitWSA initiates the use of the Winsock DLL by the current process. +// It is called from the net package at init time to avoid +// loading ws2_32.dll when net is not used. +var InitWSA = sync.OnceFunc(func() { var d syscall.WSAData e := syscall.WSAStartup(uint32(0x202), &d) if e != nil { initErr = e } checkSetFileCompletionNotificationModes() -} +}) // operation contains superset of data necessary to perform all async IO. type operation struct { diff --git a/src/internal/poll/fd_windows_test.go b/src/internal/poll/fd_windows_test.go index f0697a0d7b..1cee18dcba 100644 --- a/src/internal/poll/fd_windows_test.go +++ b/src/internal/poll/fd_windows_test.go @@ -41,6 +41,8 @@ func logFD(net string, fd *poll.FD, err error) { func init() { loggedFDs = make(map[syscall.Handle]*loggedFD) *poll.LogInitFD = logFD + + poll.InitWSA() } func findLoggedFD(h syscall.Handle) (lfd *loggedFD, found bool) { |
