sock_windows.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package net
  5. import (
  6. "internal/syscall/windows"
  7. "os"
  8. "syscall"
  9. )
  10. func maxListenerBacklog() int {
  11. // TODO: Implement this
  12. // NOTE: Never return a number bigger than 1<<16 - 1. See issue 5030.
  13. return syscall.SOMAXCONN
  14. }
  15. func sysSocket(family, sotype, proto int) (syscall.Handle, error) {
  16. s, err := wsaSocketFunc(int32(family), int32(sotype), int32(proto),
  17. nil, 0, windows.WSA_FLAG_OVERLAPPED|windows.WSA_FLAG_NO_HANDLE_INHERIT)
  18. if err == nil {
  19. return s, nil
  20. }
  21. // WSA_FLAG_NO_HANDLE_INHERIT flag is not supported on some
  22. // old versions of Windows, see
  23. // https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx
  24. // for details. Just use syscall.Socket, if windows.WSASocket failed.
  25. // See ../syscall/exec_unix.go for description of ForkLock.
  26. syscall.ForkLock.RLock()
  27. s, err = socketFunc(family, sotype, proto)
  28. if err == nil {
  29. syscall.CloseOnExec(s)
  30. }
  31. syscall.ForkLock.RUnlock()
  32. if err != nil {
  33. return syscall.InvalidHandle, os.NewSyscallError("socket", err)
  34. }
  35. return s, nil
  36. }