2012-01-10 17:53:32 -07:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
2012-01-31 22:14:04 -07:00
|
|
|
"os"
|
2012-01-10 20:55:10 -07:00
|
|
|
"syscall"
|
2012-09-10 17:56:28 -06:00
|
|
|
"unsafe"
|
2012-01-10 17:53:32 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
|
2012-01-31 22:14:04 -07:00
|
|
|
ip, err := interfaceToIPv4Addr(ifi)
|
|
|
|
if err != nil {
|
|
|
|
return os.NewSyscallError("setsockopt", err)
|
|
|
|
}
|
2012-09-10 17:56:28 -06:00
|
|
|
var a [4]byte
|
|
|
|
copy(a[:], ip.To4())
|
net: add special netFD mutex
The mutex, fdMutex, handles locking and lifetime of sysfd,
and serializes Read and Write methods.
This allows to strip 2 sync.Mutex.Lock calls,
2 sync.Mutex.Unlock calls, 1 defer and some amount
of misc overhead from every network operation.
On linux/amd64, Intel E5-2690:
benchmark old ns/op new ns/op delta
BenchmarkTCP4Persistent 9595 9454 -1.47%
BenchmarkTCP4Persistent-2 8978 8772 -2.29%
BenchmarkTCP4ConcurrentReadWrite 4900 4625 -5.61%
BenchmarkTCP4ConcurrentReadWrite-2 2603 2500 -3.96%
In general it strips 70-500 ns from every network operation depending
on processor model. On my relatively new E5-2690 it accounts to ~5%
of network op cost.
Fixes #6074.
R=golang-dev, bradfitz, alex.brainman, iant, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/12418043
2013-08-09 11:43:00 -06:00
|
|
|
if err := fd.incref(); err != nil {
|
2012-02-13 22:40:37 -07:00
|
|
|
return err
|
|
|
|
}
|
2012-01-31 22:14:04 -07:00
|
|
|
defer fd.decref()
|
2013-07-27 20:18:06 -06:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, (*byte)(unsafe.Pointer(&a[0])), 4))
|
2012-01-10 17:53:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func setIPv4MulticastLoopback(fd *netFD, v bool) error {
|
net: add special netFD mutex
The mutex, fdMutex, handles locking and lifetime of sysfd,
and serializes Read and Write methods.
This allows to strip 2 sync.Mutex.Lock calls,
2 sync.Mutex.Unlock calls, 1 defer and some amount
of misc overhead from every network operation.
On linux/amd64, Intel E5-2690:
benchmark old ns/op new ns/op delta
BenchmarkTCP4Persistent 9595 9454 -1.47%
BenchmarkTCP4Persistent-2 8978 8772 -2.29%
BenchmarkTCP4ConcurrentReadWrite 4900 4625 -5.61%
BenchmarkTCP4ConcurrentReadWrite-2 2603 2500 -3.96%
In general it strips 70-500 ns from every network operation depending
on processor model. On my relatively new E5-2690 it accounts to ~5%
of network op cost.
Fixes #6074.
R=golang-dev, bradfitz, alex.brainman, iant, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/12418043
2013-08-09 11:43:00 -06:00
|
|
|
if err := fd.incref(); err != nil {
|
2012-02-13 22:40:37 -07:00
|
|
|
return err
|
|
|
|
}
|
2012-01-31 22:14:04 -07:00
|
|
|
defer fd.decref()
|
2013-07-27 20:18:06 -06:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, boolint(v)))
|
2012-01-10 17:53:32 -07:00
|
|
|
}
|