]> Cypherpunks repositories - gostls13.git/commitdiff
net: dragonfly support
authorJoel Sing <jsing@google.com>
Fri, 23 Aug 2013 16:18:22 +0000 (02:18 +1000)
committerJoel Sing <jsing@google.com>
Fri, 23 Aug 2013 16:18:22 +0000 (02:18 +1000)
Make the net package build and work on dragonfly.

R=bradfitz
CC=golang-dev
https://golang.org/cl/13173044

34 files changed:
src/pkg/net/cgo_bsd.go
src/pkg/net/cgo_unix.go
src/pkg/net/dial_test.go
src/pkg/net/dnsclient_unix.go
src/pkg/net/dnsclient_unix_test.go
src/pkg/net/dnsconfig_unix.go
src/pkg/net/fd_poll_runtime.go
src/pkg/net/fd_posix_test.go
src/pkg/net/fd_unix.go
src/pkg/net/fd_unix_test.go
src/pkg/net/file_unix.go
src/pkg/net/interface_bsd.go
src/pkg/net/interface_bsd_test.go
src/pkg/net/interface_dragonfly.go [new file with mode: 0644]
src/pkg/net/interface_unix_test.go
src/pkg/net/iprawsock_posix.go
src/pkg/net/ipsock_posix.go
src/pkg/net/lookup_unix.go
src/pkg/net/multicast_test.go
src/pkg/net/port_unix.go
src/pkg/net/sendfile_dragonfly.go [new file with mode: 0644]
src/pkg/net/sock_bsd.go
src/pkg/net/sock_posix.go
src/pkg/net/sockopt_bsd.go
src/pkg/net/sockopt_posix.go
src/pkg/net/sockoptip_bsd.go
src/pkg/net/sockoptip_posix.go
src/pkg/net/sys_cloexec.go
src/pkg/net/tcpsock_posix.go
src/pkg/net/tcpsockopt_posix.go
src/pkg/net/tcpsockopt_unix.go
src/pkg/net/udp_test.go
src/pkg/net/udpsock_posix.go
src/pkg/net/unixsock_posix.go

index 53f8c38e3be0cb5e9590d29707d5f897eee10fa6..388eab4fe1a0f7faec1dc6d9ffc017fa80a6c2bb 100644 (file)
@@ -3,7 +3,7 @@
 // license that can be found in the LICENSE file.
 
 // +build !netgo
-// +build darwin freebsd
+// +build darwin dragonfly freebsd
 
 package net
 
index ade84162f2a7debc0f8bfdf5c395e5e5116a9218..1d736257f52c21a01d247fdefc4dc37b518ef1c8 100644 (file)
@@ -3,7 +3,7 @@
 // license that can be found in the LICENSE file.
 
 // +build !netgo
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package net
 
index c7bd4d7bfa46d268f6f588a404a7c85ab5677f81..59cd9cbe538b4fb4f9f64d4cbe0debbb0fd07793 100644 (file)
@@ -137,7 +137,7 @@ func TestSelfConnect(t *testing.T) {
                n = 1000
        }
        switch runtime.GOOS {
-       case "darwin", "freebsd", "netbsd", "openbsd", "plan9", "windows":
+       case "darwin", "dragonfly", "freebsd", "netbsd", "openbsd", "plan9", "windows":
                // Non-Linux systems take a long time to figure
                // out that there is nothing listening on localhost.
                n = 100
index 8548f50354770bef31e4860614ddbf84c2965757..f42e9d321f4ec68a47029c2351b8e0dae62e26c3 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 // DNS client: see RFC 1035.
 // Has to be linked into package net for Dial.
index e8edc862da6f437fd85590b5de61d192b7ce82f5..47dcb563bc54e8a91ee7dbd199a3ebbd8c597650 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package net
 
index bb46cc9007c621b2fa7121e23f5004fba8e7c948..2f0f6c031f13ff89fe32ee7de8333ab3b84379ea 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 // Read system DNS config from /etc/resolv.conf
 
index 97dbcf6f7110534a7f861c435e735efd89e572bb..e2b2768864afb537da731c8e6a9f9c0fec2275c1 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package net
 
index 11a7eb1b80f5dfbb83507da7c1e2b0da1ca78d05..6d2794b7121110a0ecde175e095017a0644f4e3f 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package net
 
index f475cf45dbf8da517ec10669976b9b33618e4a0f..58cfd04f35ace5c5c55fecadbc14d6222aea99dd 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package net
 
index 664ef1bf19d6348aec1badc99fb81fc7b6721d1e..65d3e69a764036a397dafbef211252c8ff0b261a 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package net
 
index fe01918a1ff087a41bfbe90023bae942e53c1e24..8fe1b0eb035f5b18d9330504c3c8bce76df32279 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package net
 
index 716b60a97f4bc25689ee28817494ae4b915cbe71..16775579d0526de2418b387b4d9e59a777fe3bce 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd netbsd openbsd
+// +build darwin dragonfly freebsd netbsd openbsd
 
 package net
 
index aa1141903b240bfffc42266ed2bcf1a714130eff..88daf73935abb79ed4f6a9c2f610b9d5d31c8805 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd netbsd openbsd
+// +build darwin dragonfly freebsd netbsd openbsd
 
 package net
 
diff --git a/src/pkg/net/interface_dragonfly.go b/src/pkg/net/interface_dragonfly.go
new file mode 100644 (file)
index 0000000..c9ce5a7
--- /dev/null
@@ -0,0 +1,12 @@
+// 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
+
+// interfaceMulticastAddrTable returns addresses for a specific
+// interface.
+func interfaceMulticastAddrTable(ifi *Interface) ([]Addr, error) {
+       // TODO(mikio): Implement this like other platforms.
+       return nil, nil
+}
index 0a453c09551d2b2c7ca699aaf5703f87ce4dd7fe..01f609f15e471a24c52be5c1129ab6f74f9f30ce 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package net
 
index 1df661c37de92c1479457187f87db13fbba48ec0..a73939fe9307a8963147a45df6bdefe4901a6d13 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package net
 
index 86cad58059b3e763244fd409521b42fbfa157903..82a2a02edbdeab36c0d3a5269886f2e41f6a59cd 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 // Internet protocol family sockets for POSIX
 
index a39e72619252f62ef14e8c831c5993d9aa8e43cb..59e9f63210c835e4956e589bc543991838f1efd6 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package net
 
index 8ff02a3c9333a53f11d07d13808920588082b37a..5660fd42f8c712feea6a4c8050444b094bc2349e 100644 (file)
@@ -158,7 +158,7 @@ func checkMulticastListener(c *UDPConn, ip IP) error {
 
 func multicastRIBContains(ip IP) (bool, error) {
        switch runtime.GOOS {
-       case "netbsd", "openbsd", "plan9", "solaris", "windows":
+       case "dragonfly", "netbsd", "openbsd", "plan9", "solaris", "windows":
                return true, nil // not implemented yet
        case "linux":
                if runtime.GOARCH == "arm" || runtime.GOARCH == "alpha" {
index 16780da1160cd81dc6065924c364ae0f5adcf589..3cd9ca2aa711122f23c1ff7dea96867c5a1bdc60 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 // Read system port mappings from /etc/services
 
diff --git a/src/pkg/net/sendfile_dragonfly.go b/src/pkg/net/sendfile_dragonfly.go
new file mode 100644 (file)
index 0000000..a2219c1
--- /dev/null
@@ -0,0 +1,103 @@
+// 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 (
+       "io"
+       "os"
+       "syscall"
+)
+
+// maxSendfileSize is the largest chunk size we ask the kernel to copy
+// at a time.
+const maxSendfileSize int = 4 << 20
+
+// 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) {
+       // DragonFly uses 0 as the "until EOF" value. If you pass in more bytes than the
+       // file contains, it will loop back to the beginning ad nauseum until it's sent
+       // exactly the number of bytes told to. As such, we need to know exactly how many
+       // bytes to send.
+       var remain int64 = 0
+
+       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
+       }
+
+       if remain == 0 {
+               fi, err := f.Stat()
+               if err != nil {
+                       return 0, err, false
+               }
+
+               remain = fi.Size()
+       }
+
+       // The other quirk with DragonFly's sendfile implementation is that it doesn't
+       // use the current position of the file -- if you pass it offset 0, it starts
+       // from offset 0. There's no way to tell it "start from current position", so
+       // we have to manage that explicitly.
+       pos, err := f.Seek(0, os.SEEK_CUR)
+       if err != nil {
+               return 0, err, false
+       }
+
+       if err := c.writeLock(); err != nil {
+               return 0, err, true
+       }
+       defer c.writeUnlock()
+
+       dst := c.sysfd
+       src := int(f.Fd())
+       for remain > 0 {
+               n := maxSendfileSize
+               if int64(n) > remain {
+                       n = int(remain)
+               }
+               pos1 := pos
+               n, err1 := syscall.Sendfile(dst, src, &pos1, n)
+               if n > 0 {
+                       pos += int64(n)
+                       written += int64(n)
+                       remain -= int64(n)
+               }
+               if n == 0 && err1 == nil {
+                       break
+               }
+               if err1 == syscall.EAGAIN {
+                       if err1 = c.pd.WaitWrite(); err1 == nil {
+                               continue
+                       }
+               }
+               if err1 == syscall.EINTR {
+                       continue
+               }
+               if err1 != nil {
+                       // This includes syscall.ENOSYS (no kernel
+                       // support) and syscall.EINVAL (fd types which
+                       // don't implement sendfile together)
+                       err = &OpError{"sendfile", c.net, c.raddr, err1}
+                       break
+               }
+       }
+       if lr != nil {
+               lr.N = remain
+       }
+       return written, err, written > 0
+}
index d99349265ebed6eeb4e43c9374b4eec3815af81d..6c37109f5e4b02d84924719372e957bfb357bb13 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd netbsd openbsd
+// +build darwin dragonfly freebsd netbsd openbsd
 
 package net
 
index 7abf79a77176911a757d4174c59351267f2bc938..a6a6b4e913e78aa54ff3376ca2dcd106be06d133 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package net
 
index 6cedc3870e52cb130b42cf2c246e77bf5620defa..ef6eb85053bc9487747c08ce369276156eaea2b8 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd netbsd openbsd
+// +build darwin dragonfly freebsd netbsd openbsd
 
 package net
 
index da2742c9a4ab0df943a32b9ec102552ab2c28347..ff3bc6899401d3786dcce3b7a27165e9138caad7 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package net
 
index ca080fd7e4da3c6d57fbb4ce1bb89e5da90ecf20..2199e480d423bd5c167d8ff2f3212111b298bf8e 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd netbsd openbsd
+// +build darwin dragonfly freebsd netbsd openbsd
 
 package net
 
index 5c2a5872f490c42781c32365696a387e21152162..c2579be9114fa4796ebaf7acbe07f542ca20d30d 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package net
 
index 17e8749087df2f41c32e47dbef9a139f899fdddb..bbfcc1a4fc42dc478e54dd603e5456425f2fac92 100644 (file)
@@ -5,7 +5,7 @@
 // This file implements sysSocket and accept for platforms that do not
 // provide a fast path for setting SetNonblock and CloseOnExec.
 
-// +build darwin freebsd netbsd openbsd
+// +build darwin dragonfly freebsd netbsd openbsd
 
 package net
 
index 7d72faade135ed2ad4dc8b3db010a0a9edef2348..39a1656b303c577cdd1bf2231a9d3ad1ad0fa2d4 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package net
 
index 8b41b2117dcdba3bb257fc3295210214702900c8..e03476ac6346aa5ad63b1207231d4ce340b437f8 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package net
 
index fba2acdb601f5022ca5c22eef7bc1ca58e9e72eb..89d9143b52e2bfb54ac301decf8112b86e163cda 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build freebsd linux netbsd
+// +build dragonfly freebsd linux netbsd
 
 package net
 
index 4278f6dd4bcb345adfa3be4fd34db3d9626f3702..f6a61ceb93115de4f1a1b7271e6b21d7255c2147 100644 (file)
@@ -224,7 +224,7 @@ func TestIPv6LinkLocalUnicastUDP(t *testing.T) {
                {"udp6", "[" + laddr + "%" + ifi.Name + "]:0", false},
        }
        switch runtime.GOOS {
-       case "darwin", "freebsd", "openbsd", "netbsd":
+       case "darwin", "dragonfly", "freebsd", "openbsd", "netbsd":
                tests = append(tests, []test{
                        {"udp", "[localhost%" + ifi.Name + "]:0", true},
                        {"udp6", "[localhost%" + ifi.Name + "]:0", true},
index 3f9230b28380486c36c20ae4a61674ac0cbf4a60..1101e3e7db10cf555975c78e6860a5fd9ba5dc8a 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package net
 
index 94296b92c793ca2538f17c4f1a8298bf0dd6a889..86dcbc1a0fdf92549db5c4530180c193e9d81538 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package net