Home | History | Annotate | Download | only in net
      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 
      5 package net
      6 
      7 import (
      8 	"internal/syscall/windows"
      9 	"os"
     10 	"syscall"
     11 )
     12 
     13 func maxListenerBacklog() int {
     14 	// TODO: Implement this
     15 	// NOTE: Never return a number bigger than 1<<16 - 1. See issue 5030.
     16 	return syscall.SOMAXCONN
     17 }
     18 
     19 func sysSocket(family, sotype, proto int) (syscall.Handle, error) {
     20 	s, err := wsaSocketFunc(int32(family), int32(sotype), int32(proto),
     21 		nil, 0, windows.WSA_FLAG_OVERLAPPED|windows.WSA_FLAG_NO_HANDLE_INHERIT)
     22 	if err == nil {
     23 		return s, nil
     24 	}
     25 	// WSA_FLAG_NO_HANDLE_INHERIT flag is not supported on some
     26 	// old versions of Windows, see
     27 	// https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx
     28 	// for details. Just use syscall.Socket, if windows.WSASocket failed.
     29 
     30 	// See ../syscall/exec_unix.go for description of ForkLock.
     31 	syscall.ForkLock.RLock()
     32 	s, err = socketFunc(family, sotype, proto)
     33 	if err == nil {
     34 		syscall.CloseOnExec(s)
     35 	}
     36 	syscall.ForkLock.RUnlock()
     37 	if err != nil {
     38 		return syscall.InvalidHandle, os.NewSyscallError("socket", err)
     39 	}
     40 	return s, nil
     41 }
     42