]> Cypherpunks repositories - gostls13.git/commitdiff
net: make UnixAddr implement sockaddr interface
authorMikio Hara <mikioh.mikioh@gmail.com>
Sun, 28 Jul 2013 07:15:07 +0000 (16:15 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Sun, 28 Jul 2013 07:15:07 +0000 (16:15 +0900)
This is in preparation for runtime-integrated network pollster for BSD
variants.

Update #5199

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/11932044

src/pkg/net/sock_posix.go
src/pkg/net/unixsock.go
src/pkg/net/unixsock_posix.go

index e484a5737e7cb9e65482403eeb884f6aa556b144..1d238c96840db3b9b3d6e62c451c6f59f5944dae 100644 (file)
@@ -11,8 +11,8 @@ import (
        "time"
 )
 
-// A sockaddr represents a TCP, UDP, IP network endpoint address that
-// can be converted into a syscall.Sockaddr.
+// A sockaddr represents a TCP, UDP, IP or Unix network endpoint
+// address that can be converted into a syscall.Sockaddr.
 type sockaddr interface {
        Addr
        family() int
index 21a19eca2c021ab79caae57635549e0153aa7df6..94c4c39ddc542cb7640888d528873b76f080abca 100644 (file)
@@ -23,13 +23,6 @@ func (a *UnixAddr) String() string {
        return a.Name
 }
 
-func (a *UnixAddr) toAddr() Addr {
-       if a == nil { // nil *UnixAddr
-               return nil // nil interface
-       }
-       return a
-}
-
 // ResolveUnixAddr parses addr as a Unix domain socket address.
 // The string net gives the network name, "unix", "unixgram" or
 // "unixpacket".
index 5db30df95fc3504c9803ad3d629f7a2193938961..497b5beea9655dd6a178752daa67c7de39d558d2 100644 (file)
@@ -13,13 +13,6 @@ import (
        "time"
 )
 
-func (a *UnixAddr) isUnnamed() bool {
-       if a == nil || a.Name == "" {
-               return true
-       }
-       return false
-}
-
 func unixSocket(net string, laddr, raddr *UnixAddr, mode string, deadline time.Time) (*netFD, error) {
        var sotype int
        switch net {
@@ -36,12 +29,12 @@ func unixSocket(net string, laddr, raddr *UnixAddr, mode string, deadline time.T
        var la, ra syscall.Sockaddr
        switch mode {
        case "dial":
-               if !laddr.isUnnamed() {
+               if !laddr.isWildcard() {
                        la = &syscall.SockaddrUnix{Name: laddr.Name}
                }
                if raddr != nil {
                        ra = &syscall.SockaddrUnix{Name: raddr.Name}
-               } else if sotype != syscall.SOCK_DGRAM || laddr.isUnnamed() {
+               } else if sotype != syscall.SOCK_DGRAM || laddr.isWildcard() {
                        return nil, &OpError{Op: mode, Net: net, Err: errMissingAddress}
                }
        case "listen":
@@ -106,6 +99,29 @@ func sotypeToNet(sotype int) string {
        }
 }
 
+func (a *UnixAddr) family() int {
+       return syscall.AF_UNIX
+}
+
+// isWildcard reports whether a is a wildcard address.
+func (a *UnixAddr) isWildcard() bool {
+       return a == nil || a.Name == ""
+}
+
+func (a *UnixAddr) sockaddr(family int) (syscall.Sockaddr, error) {
+       if a == nil {
+               return nil, nil
+       }
+       return &syscall.SockaddrUnix{Name: a.Name}, nil
+}
+
+func (a *UnixAddr) toAddr() sockaddr {
+       if a == nil {
+               return nil
+       }
+       return a
+}
+
 // UnixConn is an implementation of the Conn interface for connections
 // to Unix domain sockets.
 type UnixConn struct {