mirror of
https://github.com/golang/go.git
synced 2025-05-19 06:14:40 +00:00
This will make it possible to use the poller with the os package. This is a lot of code movement but the behavior is intended to be unchanged. Update #6817. Update #7903. Update #15021. Update #18507. Change-Id: I1413685928017c32df5654ded73a2643820977ae Reviewed-on: https://go-review.googlesource.com/36799 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
37 lines
1003 B
Go
37 lines
1003 B
Go
// Copyright 2013 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// This file implements sysSocket and accept for platforms that do not
|
|
// provide a fast path for setting SetNonblock and CloseOnExec.
|
|
|
|
// +build darwin dragonfly nacl netbsd openbsd solaris
|
|
|
|
package net
|
|
|
|
import (
|
|
"internal/poll"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
// Wrapper around the socket system call that marks the returned file
|
|
// descriptor as nonblocking and close-on-exec.
|
|
func sysSocket(family, sotype, proto int) (int, error) {
|
|
// See ../syscall/exec_unix.go for description of ForkLock.
|
|
syscall.ForkLock.RLock()
|
|
s, err := socketFunc(family, sotype, proto)
|
|
if err == nil {
|
|
syscall.CloseOnExec(s)
|
|
}
|
|
syscall.ForkLock.RUnlock()
|
|
if err != nil {
|
|
return -1, os.NewSyscallError("socket", err)
|
|
}
|
|
if err = syscall.SetNonblock(s, true); err != nil {
|
|
poll.CloseFunc(s)
|
|
return -1, os.NewSyscallError("setnonblock", err)
|
|
}
|
|
return s, nil
|
|
}
|