Source file src/net/file_unix.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  //go:build unix
     6  
     7  package net
     8  
     9  import (
    10  	"internal/poll"
    11  	"os"
    12  	"syscall"
    13  )
    14  
    15  const _SO_TYPE = syscall.SO_TYPE
    16  
    17  func dupFileSocket(f *os.File) (int, error) {
    18  	s, call, err := poll.DupCloseOnExec(int(f.Fd()))
    19  	if err != nil {
    20  		if call != "" {
    21  			err = os.NewSyscallError(call, err)
    22  		}
    23  		return -1, err
    24  	}
    25  	if err := syscall.SetNonblock(s, true); err != nil {
    26  		poll.CloseFunc(s)
    27  		return -1, os.NewSyscallError("setnonblock", err)
    28  	}
    29  	return s, nil
    30  }
    31  

View as plain text