]> Cypherpunks repositories - gostls13.git/commitdiff
runtime, net: add support for GOOS=solaris
authorAram Hăvărneanu <aram@mgk.ro>
Tue, 25 Feb 2014 03:31:01 +0000 (22:31 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 25 Feb 2014 03:31:01 +0000 (22:31 -0500)
LGTM=dave, rsc
R=golang-codereviews, minux.ma, mikioh.mikioh, dave, iant, rsc
CC=golang-codereviews
https://golang.org/cl/36030043

43 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/dnsconfig_unix.go
src/pkg/net/fd_poll_runtime.go
src/pkg/net/fd_unix.go
src/pkg/net/fd_unix_test.go
src/pkg/net/file_unix.go
src/pkg/net/interface_stub.go
src/pkg/net/ipraw_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_stub.go
src/pkg/net/sock_posix.go
src/pkg/net/sock_solaris.go [new file with mode: 0644]
src/pkg/net/sockopt_posix.go
src/pkg/net/sockopt_solaris.go [new file with mode: 0644]
src/pkg/net/sockoptip_bsd.go
src/pkg/net/sockoptip_posix.go
src/pkg/net/sys_cloexec.go
src/pkg/net/tcp_test.go
src/pkg/net/tcpsock_posix.go
src/pkg/net/tcpsockopt_posix.go
src/pkg/net/tcpsockopt_solaris.go [new file with mode: 0644]
src/pkg/net/udpsock_posix.go
src/pkg/net/unixsock_posix.go
src/pkg/runtime/defs_solaris_amd64.go
src/pkg/runtime/netpoll.goc
src/pkg/runtime/netpoll_epoll.c
src/pkg/runtime/netpoll_kqueue.c
src/pkg/runtime/netpoll_solaris.c [new file with mode: 0644]
src/pkg/runtime/netpoll_windows.c
src/pkg/runtime/os_solaris.h
src/pkg/runtime/rt0_solaris_amd64.s
src/pkg/runtime/runtime.h
src/pkg/runtime/signal_solaris_amd64.h
src/pkg/runtime/signals_solaris.h
src/pkg/runtime/sys_solaris_amd64.s
src/pkg/runtime/syscall_solaris.goc

index 388eab4fe1a0f7faec1dc6d9ffc017fa80a6c2bb..3090d3019d336d3a8e5c7f90673af447984c06d3 100644 (file)
@@ -3,7 +3,7 @@
 // license that can be found in the LICENSE file.
 
 // +build !netgo
-// +build darwin dragonfly freebsd
+// +build darwin dragonfly freebsd solaris
 
 package net
 
index 1f366ee5c6d1596dee3d623b2b8d0969ea8e4ff6..0c670982f21a80fa8b740b424f0e1a5fc58b7cac 100644 (file)
@@ -3,7 +3,7 @@
 // license that can be found in the LICENSE file.
 
 // +build !netgo
-// +build darwin dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
 
 package net
 
index 15ab10dfd4599a1a05ea8be115e9184facf7486b..9def44074cf31ef83ca60cf22a4b0830529a8380 100644 (file)
@@ -141,7 +141,7 @@ func TestSelfConnect(t *testing.T) {
                n = 1000
        }
        switch runtime.GOOS {
-       case "darwin", "dragonfly", "freebsd", "netbsd", "openbsd", "plan9", "windows":
+       case "darwin", "dragonfly", "freebsd", "netbsd", "openbsd", "plan9", "solaris", "windows":
                // Non-Linux systems take a long time to figure
                // out that there is nothing listening on localhost.
                n = 100
index a30c9a73d7e0e920f7a8a7ee33e79ff44b39b0a4..7840d4eebbd680453775cd18da16be2e1ae1729d 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 dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
 
 // DNS client: see RFC 1035.
 // Has to be linked into package net for Dial.
index 7856ebc80de5ca45bc70c63b389c86b8cc0b1152..656b270f180dbdaf3c9b3e0aca09bbbb868474c3 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 dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
 
 // Read system DNS config from /etc/resolv.conf
 
index 549e19cd3f325365e63a7ff7869269ae55bc32be..2bddc836c75a7af4492cbb5a748c74fc6a3ad991 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 dragonfly freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows solaris
 
 package net
 
index ef44d44a99bfa9cdf52690a27e9bcfe552da3c9d..f96dbf975df65f7604341aa3010140f9a88bd3d3 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 dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
 
 package net
 
index 65d3e69a764036a397dafbef211252c8ff0b261a..fe8e8ff6a88683c0e8ada5417717d236c2e26ad5 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 dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
 
 package net
 
index 38ae47f7847d1d3088b8e0d56495f8b0732f079e..214a4196c8e3cfca5376ab380ef7912c07e7de97 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 dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
 
 package net
 
index a4eb731da441ed606cd9cab8ec34ca8b8a9c83ff..31f6ee3e1c495b001537903b961e15675c09b76e 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 plan9
+// +build plan9 solaris
 
 package net
 
index ea183f1d3ebe36d741ad701c5a2890d1f5b800f3..1408b065d3ce1f95d6e0cbea60c8c077b7c1c7e4 100644 (file)
@@ -277,7 +277,7 @@ func TestIPConnRemoteName(t *testing.T) {
                }
        }
 
-       raddr := &IPAddr{IP: IPv4(127, 0, 0, 10).To4()}
+       raddr := &IPAddr{IP: IPv4(127, 0, 0, 1).To4()}
        c, err := DialIP("ip:tcp", &IPAddr{IP: IPv4(127, 0, 0, 1)}, raddr)
        if err != nil {
                t.Fatalf("DialIP failed: %v", err)
index a1a008ac413c6d12fed4b31fa982169dfe651a3c..517bea21f3944405a16bfc3904111258aaac0ca2 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 dragonfly freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
 
 package net
 
index a83e5256174fd84910063a2172c044dbfd1a8ef3..486c3f2b9a1646a25040848b2061f9a1dd3d4000 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 dragonfly freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
 
 // Internet protocol family sockets for POSIX
 
index 59e9f63210c835e4956e589bc543991838f1efd6..a54578456d7c6ac49df2a0ae56460c90afaa3e0c 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 dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
 
 package net
 
index 5660fd42f8c712feea6a4c8050444b094bc2349e..0f313cc4cb8035598b478e119858223b41e2dc1b 100644 (file)
@@ -27,6 +27,8 @@ func TestIPv4MulticastListener(t *testing.T) {
        switch runtime.GOOS {
        case "plan9":
                t.Skipf("skipping test on %q", runtime.GOOS)
+       case "solaris":
+               t.Skipf("skipping test on solaris, see issue 7399")
        }
 
        closer := func(cs []*UDPConn) {
@@ -93,8 +95,10 @@ var ipv6MulticastListenerTests = []struct {
 // port.
 func TestIPv6MulticastListener(t *testing.T) {
        switch runtime.GOOS {
-       case "plan9", "solaris":
+       case "plan9":
                t.Skipf("skipping test on %q", runtime.GOOS)
+       case "solaris":
+               t.Skipf("skipping test on solaris, see issue 7399")
        }
        if !supportsIPv6 {
                t.Skip("ipv6 is not supported")
index 3cd9ca2aa711122f23c1ff7dea96867c5a1bdc60..a1beb840d595e82eb866c2b18f939331e30b8e76 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 dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
 
 // Read system port mappings from /etc/services
 
@@ -10,12 +10,16 @@ package net
 
 import "sync"
 
-var services map[string]map[string]int
+// services contains minimal mappings between services names and port
+// numbers for platforms that don't have a complete list of port numbers
+// (some Solaris distros).
+var services = map[string]map[string]int{
+       "tcp": {"http": 80},
+}
 var servicesError error
 var onceReadServices sync.Once
 
 func readServices() {
-       services = make(map[string]map[string]int)
        var file *file
        if file, servicesError = open("/etc/services"); servicesError != nil {
                return
index 3660849c182c5cc4ee93a86eee699ed9955182f6..d7401e274da37a7d95539528c911f7f3a80a5dfc 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 netbsd openbsd
+// +build darwin netbsd openbsd solaris
 
 package net
 
index c2d343c5858076c5653c5b48b875b7ae0ca7adaa..290596247efbb8cd3ec8b801c193073e82fd0ff4 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 dragonfly freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
 
 package net
 
diff --git a/src/pkg/net/sock_solaris.go b/src/pkg/net/sock_solaris.go
new file mode 100644 (file)
index 0000000..90fe9de
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2009 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 "syscall"
+
+func maxListenerBacklog() int {
+       // TODO: Implement this
+       // NOTE: Never return a number bigger than 1<<16 - 1. See issue 5030.
+       return syscall.SOMAXCONN
+}
index ff3bc6899401d3786dcce3b7a27165e9138caad7..1654d1b85e46c6481e0b7ebb5c009b3e205faa0f 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 dragonfly freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
 
 package net
 
diff --git a/src/pkg/net/sockopt_solaris.go b/src/pkg/net/sockopt_solaris.go
new file mode 100644 (file)
index 0000000..54c20b1
--- /dev/null
@@ -0,0 +1,32 @@
+// 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 (
+       "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 2199e480d423bd5c167d8ff2f3212111b298bf8e..0fa74718a6a38ffe5ea6dc4f8f2b36e5fbf46e9e 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 dragonfly freebsd netbsd openbsd
+// +build darwin dragonfly freebsd netbsd openbsd solaris
 
 package net
 
index c2579be9114fa4796ebaf7acbe07f542ca20d30d..f38bb4f04069f51f4765c2c855e90750e7d8c32f 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 dragonfly freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
 
 package net
 
index bbfcc1a4fc42dc478e54dd603e5456425f2fac92..cdc669b6210314038a074e947ba5d3d48ac05f45 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 dragonfly freebsd netbsd openbsd
+// +build darwin dragonfly freebsd netbsd openbsd solaris
 
 package net
 
index 62fd99f5c0bb2442e1423207a3041e3b19f279ce..d3628748a73388dca5efb1a9318b911f3beefea3 100644 (file)
@@ -440,6 +440,9 @@ func TestIPv6LinkLocalUnicastTCP(t *testing.T) {
 }
 
 func TestTCPConcurrentAccept(t *testing.T) {
+       if runtime.GOOS == "solaris" {
+               t.Skip("skipping on Solaris, see issue 7400")
+       }
        defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(4))
        ln, err := Listen("tcp", "127.0.0.1:0")
        if err != nil {
index 00c692e423377d12d7ca4bce9d29018f0b1498e3..3727e470e63452c175df667cc71395b5e349915a 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 dragonfly freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
 
 package net
 
index e03476ac6346aa5ad63b1207231d4ce340b437f8..0abf3f97f6b4e028f5ddfa0c792b951140453d1a 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 dragonfly freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
 
 package net
 
diff --git a/src/pkg/net/tcpsockopt_solaris.go b/src/pkg/net/tcpsockopt_solaris.go
new file mode 100644 (file)
index 0000000..eaab6b6
--- /dev/null
@@ -0,0 +1,27 @@
+// 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.
+
+// TCP socket options for solaris
+
+package net
+
+import (
+       "os"
+       "syscall"
+       "time"
+)
+
+// Set keep alive period.
+func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
+       if err := fd.incref(); err != nil {
+               return err
+       }
+       defer fd.decref()
+
+       // The kernel expects seconds so round to next highest second.
+       d += (time.Second - time.Nanosecond)
+       secs := int(d.Seconds())
+
+       return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.SO_KEEPALIVE, secs))
+}
index 142da8186f1634dd21907dfc176ba117ed06bdb3..11f9621dc363c966355a2673176fcbf6a087fb72 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 dragonfly freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
 
 package net
 
index 54d9d16c99e69702b534533a440ff4a3f6b96de8..5f1503acab969619a497051199f1361811d9953b 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 dragonfly freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
 
 package net
 
index f0265de931d66abfb6bbccbd67405678e71435a4..04931788805ce9d6a51e8cf219423bd1c109db03 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2013 The Go Authors. All rights reserved.
+// 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.
 
index e78c02c9a78983bf758cd0de4fcd6fef523aefb1..9cc5eb5a36b4614a26228eeeafb7d3201be0cdb2 100644 (file)
@@ -58,6 +58,7 @@ struct PollDesc
        G*      wg;     // READY, WAIT, G waiting for write or nil
        Timer   wt;     // write deadline timer
        int64   wd;     // write deadline
+       void*   user;   // user settable cookie
 };
 
 static struct
@@ -141,7 +142,7 @@ func runtime_pollWait(pd *PollDesc, mode int) (err int) {
        if(err == 0) {
                // As for now only Solaris uses level-triggered IO.
                if(Solaris)
-                       runtime·netpollarm(pd->fd, mode);
+                       runtime·netpollarm(pd, mode);
                while(!netpollblock(pd, mode, false)) {
                        err = checkerr(pd, mode);
                        if(err != 0)
@@ -256,6 +257,12 @@ runtime·netpollfd(PollDesc *pd)
        return pd->fd;
 }
 
+void**
+runtime·netpolluser(PollDesc *pd)
+{
+       return &pd->user;
+}
+
 // make pd ready, newly runnable goroutines (if any) are enqueued info gpp list
 void
 runtime·netpollready(G **gpp, PollDesc *pd, int32 mode)
index 318e0692991fbb49557cf94eb347ea660c90f1b0..9ea5e1a59585d280c11917e434b0430172a0b962 100644 (file)
@@ -53,9 +53,9 @@ runtime·netpollclose(uintptr fd)
 }
 
 void
-runtime·netpollarm(uintptr fd, int32 mode)
+runtime·netpollarm(PollDesc* pd, int32 mode)
 {
-       USED(fd, mode);
+       USED(pd, mode);
        runtime·throw("unused");
 }
 
index 7c5f12a1bd9411632c93190ed5ed1cbe690c25ae..171346cce28bf451f56a1291b9c04701021f2ccc 100644 (file)
@@ -60,9 +60,9 @@ runtime·netpollclose(uintptr fd)
 }
 
 void
-runtime·netpollarm(uintptr fd, int32 mode)
+runtime·netpollarm(PollDesc* pd, int32 mode)
 {
-       USED(fd, mode);
+       USED(pd, mode);
        runtime·throw("unused");
 }
 
diff --git a/src/pkg/runtime/netpoll_solaris.c b/src/pkg/runtime/netpoll_solaris.c
new file mode 100644 (file)
index 0000000..f745f23
--- /dev/null
@@ -0,0 +1,188 @@
+// 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.
+
+#include "runtime.h"
+#include "arch_GOARCH.h"
+#include "defs_GOOS_GOARCH.h"
+#include "os_GOOS.h"
+
+#pragma dynimport libc·fcntl fcntl "libc.so"
+#pragma dynimport libc·port_create port_create "libc.so"
+#pragma dynimport libc·port_associate port_associate "libc.so"
+#pragma dynimport libc·port_dissociate port_dissociate "libc.so"
+#pragma dynimport libc·port_getn port_getn "libc.so"
+extern uintptr libc·fcntl;
+extern uintptr libc·port_create;
+extern uintptr libc·port_associate;
+extern uintptr libc·port_dissociate;
+extern uintptr libc·port_getn;
+
+#define errno (*m->perrno)
+
+int32
+runtime·fcntl(int32 fd, int32 cmd, uintptr arg)
+{
+       return runtime·sysvicall6(libc·fcntl, 3,
+           (uintptr)fd, (uintptr)cmd, (uintptr)arg);
+}
+
+int32
+runtime·port_create(void)
+{
+       return runtime·sysvicall6(libc·port_create, 0);
+}
+
+int32
+runtime·port_associate(int32 port, int32 source, uintptr object, int32 events, uintptr user)
+{
+       return runtime·sysvicall6(libc·port_associate,
+           5, (uintptr)port, (uintptr)source, object, (uintptr)events, user);
+}
+
+int32
+runtime·port_dissociate(int32 port, int32 source, uintptr object)
+{
+       return runtime·sysvicall6(libc·port_dissociate,
+           3, (uintptr)port, (uintptr)source, object);
+}
+
+int32
+runtime·port_getn(int32 port, PortEvent *evs, uint32 max, uint32 *nget, Timespec *timeout)
+{
+       return runtime·sysvicall6(libc·port_getn, 5, (uintptr)port,
+           (uintptr)evs, (uintptr)max, (uintptr)nget, (uintptr)timeout);
+}
+
+static int32 portfd = -1;
+
+void
+runtime·netpollinit(void)
+{
+       if((portfd = runtime·port_create()) >= 0) {
+               runtime·fcntl(portfd, F_SETFD, FD_CLOEXEC);
+               return;
+       }
+
+       runtime·printf("netpollinit: failed to create port (%d)\n", errno);
+       runtime·throw("netpollinit: failed to create port");
+}
+
+int32
+runtime·netpollopen(uintptr fd, PollDesc *pd)
+{
+       uint32 events = POLLIN | POLLOUT;
+       *runtime·netpolluser(pd) = (void*)events;
+
+       return runtime·port_associate(portfd, PORT_SOURCE_FD, fd, events, (uintptr)pd);
+}
+
+int32
+runtime·netpollclose(uintptr fd)
+{
+       return runtime·port_dissociate(portfd, PORT_SOURCE_FD, fd);
+}
+
+void
+runtime·netpollupdate(PollDesc* pd, uint32 set, uint32 clear)
+{
+       uint32 *ep, old, events;
+       uintptr fd = runtime·netpollfd(pd);
+       ep = (uint32*)runtime·netpolluser(pd);
+
+       do {
+               old = *ep;
+               events = (old & ~clear) | set;
+               if(old == events)
+                       return;
+
+               if(events && runtime·port_associate(portfd, PORT_SOURCE_FD, fd, events, (uintptr)pd) != 0) {
+                       runtime·printf("netpollupdate: failed to associate (%d)\n", errno);
+                       runtime·throw("netpollupdate: failed to associate");
+               }
+       } while(runtime·cas(ep, old, events) != events);
+}
+
+void
+runtime·netpollarm(PollDesc* pd, int32 mode)
+{
+       switch(mode) {
+       case 'r':
+               runtime·netpollupdate(pd, POLLIN, 0);
+               break;
+       case 'w':
+               runtime·netpollupdate(pd, POLLOUT, 0);
+               break;
+       default:
+               runtime·throw("netpollarm: bad mode");
+       }
+}
+
+// polls for ready network connections
+// returns list of goroutines that become runnable
+G*
+runtime·netpoll(bool block)
+{
+       static int32 lasterr;
+       PortEvent events[128], *ev;
+       PollDesc *pd;
+       int32 i, mode;
+       uint32 n;
+       Timespec *wait = nil, zero;
+       G *gp;
+
+       if(portfd == -1)
+               return (nil);
+
+       if(!block) {
+               zero.tv_sec = 0;
+               zero.tv_nsec = 0;
+               wait = &zero;
+       }
+
+retry:
+       n = 1;
+
+       if(runtime·port_getn(portfd, events, nelem(events), &n, wait) < 0) {
+               if(errno != EINTR && errno != lasterr) {
+                       lasterr = errno;
+                       runtime·printf("runtime: port_getn on fd %d "
+                           "failed with %d\n", portfd, errno);
+               }
+               goto retry;
+       }
+
+       gp = nil;
+
+       for(i = 0; i < n; i++) {
+               ev = &events[i];
+
+               if(ev->portev_events == 0)
+                       continue;
+
+               if((pd = (PollDesc *)ev->portev_user) == nil)
+                       continue;
+
+               mode = 0;
+
+               if(ev->portev_events & (POLLIN|POLLHUP|POLLERR))
+                       mode += 'r';
+
+               if(ev->portev_events & (POLLOUT|POLLHUP|POLLERR))
+                       mode += 'w';
+
+               //
+               // To effect edge-triggered events, we need to be sure to
+               // update our association with whatever events were not
+               // set with the event.
+               //
+               runtime·netpollupdate(pd, 0, ev->portev_events & (POLLIN|POLLOUT));
+
+               if(mode)
+                       runtime·netpollready(&gp, pd, mode);
+       }
+
+       if(block && gp == nil)
+               goto retry;
+       return gp;
+}
index a9f828c706d29ac917f81931c76417a1b18da26e..f3cd15c7a95372091da437fb3e6a2bff28e2cfc2 100644 (file)
@@ -73,9 +73,9 @@ runtime·netpollclose(uintptr fd)
 }
 
 void
-runtime·netpollarm(uintptr fd, int32 mode)
+runtime·netpollarm(PollDesc* pd, int32 mode)
 {
-       USED(fd, mode);
+       USED(pd, mode);
        runtime·throw("unused");
 }
 
index 47c712b6afef06b44e08560976742d487b2ef0e3..f3fae5da2a914f7f50d6dea5a1ec65c9e29e6f25 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2013 The Go Authors. All rights reserved.
+// 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.
 
index 32fc8333f431d196645b4126111d2c78eba83f68..4aca991f083d2cd365871a6b877c938e65fd4a77 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2013 The Go Authors. All rights reserved.
+// 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.
 
index 8d07294e81b91b95619d334702d4894e6e68f776..c9887b66372ce328a22620c97512f59590353489 100644 (file)
@@ -919,7 +919,8 @@ int32       runtime·netpollopen(uintptr, PollDesc*);
 int32   runtime·netpollclose(uintptr);
 void   runtime·netpollready(G**, PollDesc*, int32);
 uintptr        runtime·netpollfd(PollDesc*);
-void   runtime·netpollarm(uintptr, int32);
+void   runtime·netpollarm(PollDesc*, int32);
+void** runtime·netpolluser(PollDesc*);
 void   runtime·crash(void);
 void   runtime·parsedebugvars(void);
 void   _rt0_go(void);
index df54a7d14996d3ad328e8f7e6804a9136f5c271a..c2e0a154976bcc469ace4549319e7d9f26224675 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2013 The Go Authors. All rights reserved.
+// 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.
 
index 75304644a5ec238bef7a0e0915e601ae1ae9f1b7..c272cad2928dd81650fb63f8c3950019079ed04b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2013 The Go Authors. All rights reserved.
+// 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.
 
index ffe2df43fb3b0519ac9dc2c969c48306593188d4..21517693b2e2042da8c1a02c7e15f30954303ca4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2013 The Go Authors. All rights reserved.
+// 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.
 //
index 5fe3aa3ebc6f8d780d59bade41fb762c8829c60c..cd30dd17889f1722768b8b50dec19f7eeac7b722 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2013 The Go Authors. All rights reserved.
+// 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.
 
@@ -50,7 +50,7 @@ extern uintptr libc·forkx;
 extern uintptr libc·wait4;
 extern uintptr libc·write;
 
-func Sysvicall6(func uintptr, nargs uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr, a6 uintptr) (r1 uintptr, r2 uintptr, err uintptr)
+func sysvicall6(func uintptr, nargs uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr, a6 uintptr) (r1 uintptr, r2 uintptr, err uintptr)
 {
        LibCall c;
 
@@ -69,7 +69,7 @@ func Sysvicall6(func uintptr, nargs uintptr, a1 uintptr, a2 uintptr, a3 uintptr,
 }
 
 #pragma textflag NOSPLIT
-func RawSysvicall6(func uintptr, nargs uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr, a6 uintptr) (r1 uintptr, r2 uintptr, err uintptr)
+func rawSysvicall6(func uintptr, nargs uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr, a6 uintptr) (r1 uintptr, r2 uintptr, err uintptr)
 {
        LibCall c;