Source file src/net/file_windows.go

     1  // Copyright 2011 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  const _SO_TYPE = windows.SO_TYPE
    14  
    15  func dupSocket(h syscall.Handle) (syscall.Handle, error) {
    16  	var info syscall.WSAProtocolInfo
    17  	err := windows.WSADuplicateSocket(h, uint32(syscall.Getpid()), &info)
    18  	if err != nil {
    19  		return 0, err
    20  	}
    21  	return windows.WSASocket(-1, -1, -1, &info, 0, windows.WSA_FLAG_OVERLAPPED|windows.WSA_FLAG_NO_HANDLE_INHERIT)
    22  }
    23  
    24  func dupFileSocket(f *os.File) (syscall.Handle, error) {
    25  	// The resulting handle should not be associated to an IOCP, else the IO operations
    26  	// will block an OS thread, and that's not what net package users expect.
    27  	h, err := dupSocket(syscall.Handle(f.Fd()))
    28  	if err != nil {
    29  		return 0, err
    30  	}
    31  	return h, nil
    32  }
    33  

View as plain text