Index: gcc-8-8-20171108-1.1/src/libgo/go/net/cgo_gnu.go =================================================================== --- /dev/null +++ gcc-8-8-20171108-1.1/src/libgo/go/net/cgo_gnu.go @@ -0,0 +1,17 @@ +// Copyright 2011 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 is derived from cgo_bsd.go + +// +build cgo,!netgo +// +build gnu + +package net + +/* +#include +*/ + +import "syscall" + +const cgoAddrInfoFlags = syscall.AI_CANONNAME | syscall.AI_V4MAPPED | syscall.AI_ALL Index: gcc-8-8-20171108-1.1/src/libgo/go/net/sendfile_gnu.go =================================================================== --- /dev/null +++ gcc-8-8-20171108-1.1/src/libgo/go/net/sendfile_gnu.go @@ -0,0 +1,42 @@ +// Copyright 2011 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 is identical to sendfile_linux.go + +package net + +import ( + "internal/poll" + "io" + "os" +) + +// sendFile copies the contents of r to c using the sendfile +// system call to minimize copies. +// +// if handled == true, sendFile returns the number of bytes copied and any +// non-EOF error. +// +// if handled == false, sendFile performed no work. +func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) { + var remain int64 = 1 << 62 // by default, copy until EOF + + lr, ok := r.(*io.LimitedReader) + if ok { + remain, r = lr.N, lr.R + if remain <= 0 { + return 0, nil, true + } + } + f, ok := r.(*os.File) + if !ok { + return 0, nil, false + } + + written, err = poll.SendFile(&c.pfd, int(f.Fd()), remain) + + if lr != nil { + lr.N = remain - written + } + return written, wrapSyscallError("sendfile", err), written > 0 +} Index: gcc-8-8-20171108-1.1/src/libgo/go/net/sock_gnu.go =================================================================== --- /dev/null +++ gcc-8-8-20171108-1.1/src/libgo/go/net/sock_gnu.go @@ -0,0 +1,15 @@ +// Copyright 2014 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 is derived from sock_stub.go + +// +build gnu + +package net + +import "syscall" + +func maxListenerBacklog() int { + // From /usr/include/i386-gnu/bits/socket.h + return syscall.SOMAXCONN +} Index: gcc-8-8-20171108-1.1/src/libgo/go/net/sockopt_gnu.go =================================================================== --- /dev/null +++ gcc-8-8-20171108-1.1/src/libgo/go/net/sockopt_gnu.go @@ -0,0 +1,33 @@ +// Copyright 2011 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 is identical to sockopt_linux.go + +package net + +import ( + "os" + "syscall" +) + +func setDefaultSockopts(s, family, sotype int, ipv6only bool) error { + if family == syscall.AF_INET6 && sotype != syscall.SOCK_RAW { + // Allow both IP versions even if the OS default + // is otherwise. Note that some operating systems + // never admit this option. + syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, boolint(ipv6only)) + } + // Allow broadcast. + return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1)) +} + +func setDefaultListenerSockopts(s int) error { + // Allow reuse of recently-used addresses. + return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)) +} + +func setDefaultMulticastSockopts(s int) error { + // Allow multicast UDP and raw IP datagram sockets to listen + // concurrently across multiple listeners. + return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)) +} Index: gcc-8-8-20171108-1.1/src/libgo/go/net/sockoptip_gnu.go =================================================================== --- /dev/null +++ gcc-8-8-20171108-1.1/src/libgo/go/net/sockoptip_gnu.go @@ -0,0 +1,31 @@ +// Copyright 2011 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 is identical to sockoptip_bsd.go + +// +build gnu + +package net + +import ( + "runtime" + "syscall" +) + +func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error { + ip, err := interfaceToIPv4Addr(ifi) + if err != nil { + return wrapSyscallError("setsockopt", err) + } + var a [4]byte + copy(a[:], ip.To4()) + err = fd.pfd.SetsockoptInet4Addr(syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, a) + runtime.KeepAlive(fd) + return wrapSyscallError("setsockopt", err) +} + +func setIPv4MulticastLoopback(fd *netFD, v bool) error { + err := fd.pfd.SetsockoptByte(syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, byte(boolint(v))) + runtime.KeepAlive(fd) + return wrapSyscallError("setsockopt", err) +} Index: gcc-8-8-20171108-1.1/src/libgo/go/internal/poll/sendfile_gnu.go =================================================================== --- /dev/null +++ gcc-8-8-20171108-1.1/src/libgo/go/internal/poll/sendfile_gnu.go @@ -0,0 +1,51 @@ +// Copyright 2011 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 is identical to sendfile_linux.go + +package poll + +import "syscall" + +// maxSendfileSize is the largest chunk size we ask the kernel to copy +// at a time. +const maxSendfileSize int = 4 << 20 + +// SendFile wraps the sendfile system call. +func SendFile(dstFD *FD, src int, remain int64) (int64, error) { + if err := dstFD.writeLock(); err != nil { + return 0, err + } + defer dstFD.writeUnlock() + + dst := int(dstFD.Sysfd) + var written int64 + var err error + for remain > 0 { + n := maxSendfileSize + if int64(n) > remain { + n = int(remain) + } + n, err1 := syscall.Sendfile(dst, src, nil, n) + if n > 0 { + written += int64(n) + remain -= int64(n) + } + if n == 0 && err1 == nil { + break + } + if err1 == syscall.EAGAIN { + if err1 = dstFD.pd.waitWrite(dstFD.isFile); err1 == nil { + continue + } + } + if err1 != nil { + // This includes syscall.ENOSYS (no kernel + // support) and syscall.EINVAL (fd types which + // don't implement sendfile) + err = err1 + break + } + } + return written, err +}