2011-09-16 17:47:21 +02:00
|
|
|
// 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.
|
|
|
|
|
2012-01-13 06:11:45 +01:00
|
|
|
// +build darwin freebsd linux netbsd openbsd windows
|
2011-10-27 01:57:58 +02:00
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
2012-12-22 02:15:33 +01:00
|
|
|
"errors"
|
2011-09-16 17:47:21 +02:00
|
|
|
"os"
|
|
|
|
"syscall"
|
2012-01-25 22:54:22 +01:00
|
|
|
"time"
|
2011-09-16 17:47:21 +02:00
|
|
|
)
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
func (a *UnixAddr) isUnnamed() bool {
|
|
|
|
if a == nil || a.Name == "" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
func unixSocket(net string, laddr, raddr *UnixAddr, mode string, deadline time.Time) (*netFD, error) {
|
2012-01-25 22:54:22 +01:00
|
|
|
var sotype int
|
2011-09-16 17:47:21 +02:00
|
|
|
switch net {
|
|
|
|
case "unix":
|
2012-01-25 22:54:22 +01:00
|
|
|
sotype = syscall.SOCK_STREAM
|
2011-09-16 17:47:21 +02:00
|
|
|
case "unixgram":
|
2012-01-25 22:54:22 +01:00
|
|
|
sotype = syscall.SOCK_DGRAM
|
2011-09-16 17:47:21 +02:00
|
|
|
case "unixpacket":
|
2012-01-25 22:54:22 +01:00
|
|
|
sotype = syscall.SOCK_SEQPACKET
|
2012-12-22 02:15:33 +01:00
|
|
|
default:
|
|
|
|
return nil, UnknownNetworkError(net)
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var la, ra syscall.Sockaddr
|
|
|
|
switch mode {
|
|
|
|
case "dial":
|
2013-07-16 08:54:42 +02:00
|
|
|
if !laddr.isUnnamed() {
|
2011-09-16 17:47:21 +02:00
|
|
|
la = &syscall.SockaddrUnix{Name: laddr.Name}
|
|
|
|
}
|
|
|
|
if raddr != nil {
|
|
|
|
ra = &syscall.SockaddrUnix{Name: raddr.Name}
|
2013-07-16 08:54:42 +02:00
|
|
|
} else if sotype != syscall.SOCK_DGRAM || laddr.isUnnamed() {
|
2011-12-03 03:17:34 +01:00
|
|
|
return nil, &OpError{Op: mode, Net: net, Err: errMissingAddress}
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
case "listen":
|
|
|
|
la = &syscall.SockaddrUnix{Name: laddr.Name}
|
2012-12-22 02:15:33 +01:00
|
|
|
default:
|
|
|
|
return nil, errors.New("unknown mode: " + mode)
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
f := sockaddrToUnix
|
2012-01-25 22:54:22 +01:00
|
|
|
if sotype == syscall.SOCK_DGRAM {
|
2011-09-16 17:47:21 +02:00
|
|
|
f = sockaddrToUnixgram
|
2012-01-25 22:54:22 +01:00
|
|
|
} else if sotype == syscall.SOCK_SEQPACKET {
|
2011-09-16 17:47:21 +02:00
|
|
|
f = sockaddrToUnixpacket
|
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
fd, err := socket(net, syscall.AF_UNIX, sotype, 0, false, la, ra, deadline, f)
|
2012-03-02 21:01:37 +01:00
|
|
|
if err != nil {
|
2012-12-22 02:15:33 +01:00
|
|
|
goto error
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
return fd, nil
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
error:
|
2011-09-16 17:47:21 +02:00
|
|
|
addr := raddr
|
2012-12-22 02:15:33 +01:00
|
|
|
switch mode {
|
|
|
|
case "listen":
|
2011-09-16 17:47:21 +02:00
|
|
|
addr = laddr
|
|
|
|
}
|
2012-03-02 21:01:37 +01:00
|
|
|
return nil, &OpError{Op: mode, Net: net, Addr: addr, Err: err}
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func sockaddrToUnix(sa syscall.Sockaddr) Addr {
|
|
|
|
if s, ok := sa.(*syscall.SockaddrUnix); ok {
|
2013-07-16 08:54:42 +02:00
|
|
|
return &UnixAddr{Name: s.Name, Net: "unix"}
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func sockaddrToUnixgram(sa syscall.Sockaddr) Addr {
|
|
|
|
if s, ok := sa.(*syscall.SockaddrUnix); ok {
|
2013-07-16 08:54:42 +02:00
|
|
|
return &UnixAddr{Name: s.Name, Net: "unixgram"}
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func sockaddrToUnixpacket(sa syscall.Sockaddr) Addr {
|
|
|
|
if s, ok := sa.(*syscall.SockaddrUnix); ok {
|
2013-07-16 08:54:42 +02:00
|
|
|
return &UnixAddr{Name: s.Name, Net: "unixpacket"}
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2012-01-25 22:54:22 +01:00
|
|
|
func sotypeToNet(sotype int) string {
|
|
|
|
switch sotype {
|
2011-09-16 17:47:21 +02:00
|
|
|
case syscall.SOCK_STREAM:
|
|
|
|
return "unix"
|
|
|
|
case syscall.SOCK_DGRAM:
|
|
|
|
return "unixgram"
|
2013-07-16 08:54:42 +02:00
|
|
|
case syscall.SOCK_SEQPACKET:
|
|
|
|
return "unixpacket"
|
2011-09-16 17:47:21 +02:00
|
|
|
default:
|
2012-01-25 22:54:22 +01:00
|
|
|
panic("sotypeToNet unknown socket type")
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// UnixConn is an implementation of the Conn interface for connections
|
|
|
|
// to Unix domain sockets.
|
2011-09-16 17:47:21 +02:00
|
|
|
type UnixConn struct {
|
2012-10-23 06:31:11 +02:00
|
|
|
conn
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
|
2012-10-23 06:31:11 +02:00
|
|
|
func newUnixConn(fd *netFD) *UnixConn { return &UnixConn{conn{fd}} }
|
2011-09-16 17:47:21 +02:00
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// ReadFromUnix reads a packet from c, copying the payload into b. It
|
|
|
|
// returns the number of bytes copied into b and the source address of
|
|
|
|
// the packet.
|
2011-09-16 17:47:21 +02:00
|
|
|
//
|
2012-12-22 02:15:33 +01:00
|
|
|
// ReadFromUnix can be made to time out and return an error with
|
|
|
|
// Timeout() == true after a fixed time limit; see SetDeadline and
|
|
|
|
// SetReadDeadline.
|
2011-12-03 03:17:34 +01:00
|
|
|
func (c *UnixConn) ReadFromUnix(b []byte) (n int, addr *UnixAddr, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
if !c.ok() {
|
2012-03-02 21:01:37 +01:00
|
|
|
return 0, nil, syscall.EINVAL
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
n, sa, err := c.fd.ReadFrom(b)
|
|
|
|
switch sa := sa.(type) {
|
|
|
|
case *syscall.SockaddrUnix:
|
2013-07-16 08:54:42 +02:00
|
|
|
if sa.Name != "" {
|
|
|
|
addr = &UnixAddr{Name: sa.Name, Net: sotypeToNet(c.fd.sotype)}
|
|
|
|
}
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-02-09 09:19:58 +01:00
|
|
|
// ReadFrom implements the PacketConn ReadFrom method.
|
2013-07-16 08:54:42 +02:00
|
|
|
func (c *UnixConn) ReadFrom(b []byte) (int, Addr, error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
if !c.ok() {
|
2012-03-02 21:01:37 +01:00
|
|
|
return 0, nil, syscall.EINVAL
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
n, addr, err := c.ReadFromUnix(b)
|
|
|
|
return n, addr.toAddr(), err
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// ReadMsgUnix reads a packet from c, copying the payload into b and
|
|
|
|
// the associated out-of-band data into oob. It returns the number of
|
|
|
|
// bytes copied into b, the number of bytes copied into oob, the flags
|
|
|
|
// that were set on the packet, and the source address of the packet.
|
|
|
|
func (c *UnixConn) ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAddr, err error) {
|
|
|
|
if !c.ok() {
|
|
|
|
return 0, 0, 0, nil, syscall.EINVAL
|
|
|
|
}
|
|
|
|
n, oobn, flags, sa, err := c.fd.ReadMsg(b, oob)
|
|
|
|
switch sa := sa.(type) {
|
|
|
|
case *syscall.SockaddrUnix:
|
2013-07-16 08:54:42 +02:00
|
|
|
if sa.Name != "" {
|
|
|
|
addr = &UnixAddr{Name: sa.Name, Net: sotypeToNet(c.fd.sotype)}
|
|
|
|
}
|
2012-12-22 02:15:33 +01:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
// WriteToUnix writes a packet to addr via c, copying the payload from b.
|
|
|
|
//
|
2012-12-22 02:15:33 +01:00
|
|
|
// WriteToUnix can be made to time out and return an error with
|
|
|
|
// Timeout() == true after a fixed time limit; see SetDeadline and
|
|
|
|
// SetWriteDeadline. On packet-oriented connections, write timeouts
|
|
|
|
// are rare.
|
2011-12-03 03:17:34 +01:00
|
|
|
func (c *UnixConn) WriteToUnix(b []byte, addr *UnixAddr) (n int, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
if !c.ok() {
|
2012-03-02 21:01:37 +01:00
|
|
|
return 0, syscall.EINVAL
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
2012-01-25 22:54:22 +01:00
|
|
|
if addr.Net != sotypeToNet(c.fd.sotype) {
|
2012-03-02 21:01:37 +01:00
|
|
|
return 0, syscall.EAFNOSUPPORT
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
sa := &syscall.SockaddrUnix{Name: addr.Name}
|
|
|
|
return c.fd.WriteTo(b, sa)
|
|
|
|
}
|
|
|
|
|
2012-02-09 09:19:58 +01:00
|
|
|
// WriteTo implements the PacketConn WriteTo method.
|
2011-12-03 03:17:34 +01:00
|
|
|
func (c *UnixConn) WriteTo(b []byte, addr Addr) (n int, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
if !c.ok() {
|
2012-03-02 21:01:37 +01:00
|
|
|
return 0, syscall.EINVAL
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
a, ok := addr.(*UnixAddr)
|
|
|
|
if !ok {
|
2012-03-02 21:01:37 +01:00
|
|
|
return 0, &OpError{"write", c.fd.net, addr, syscall.EINVAL}
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
return c.WriteToUnix(b, a)
|
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// WriteMsgUnix writes a packet to addr via c, copying the payload
|
|
|
|
// from b and the associated out-of-band data from oob. It returns
|
|
|
|
// the number of payload and out-of-band bytes written.
|
2011-12-03 03:17:34 +01:00
|
|
|
func (c *UnixConn) WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
if !c.ok() {
|
2012-03-02 21:01:37 +01:00
|
|
|
return 0, 0, syscall.EINVAL
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
if addr != nil {
|
2012-01-25 22:54:22 +01:00
|
|
|
if addr.Net != sotypeToNet(c.fd.sotype) {
|
2012-03-02 21:01:37 +01:00
|
|
|
return 0, 0, syscall.EAFNOSUPPORT
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
sa := &syscall.SockaddrUnix{Name: addr.Name}
|
|
|
|
return c.fd.WriteMsg(b, oob, sa)
|
|
|
|
}
|
|
|
|
return c.fd.WriteMsg(b, oob, nil)
|
|
|
|
}
|
|
|
|
|
2012-10-23 06:31:11 +02:00
|
|
|
// CloseRead shuts down the reading side of the Unix domain connection.
|
|
|
|
// Most callers should just use Close.
|
|
|
|
func (c *UnixConn) CloseRead() error {
|
|
|
|
if !c.ok() {
|
|
|
|
return syscall.EINVAL
|
|
|
|
}
|
|
|
|
return c.fd.CloseRead()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CloseWrite shuts down the writing side of the Unix domain connection.
|
|
|
|
// Most callers should just use Close.
|
|
|
|
func (c *UnixConn) CloseWrite() error {
|
|
|
|
if !c.ok() {
|
|
|
|
return syscall.EINVAL
|
|
|
|
}
|
|
|
|
return c.fd.CloseWrite()
|
|
|
|
}
|
2011-09-16 17:47:21 +02:00
|
|
|
|
|
|
|
// DialUnix connects to the remote address raddr on the network net,
|
2012-12-22 02:15:33 +01:00
|
|
|
// which must be "unix", "unixgram" or "unixpacket". If laddr is not
|
|
|
|
// nil, it is used as the local address for the connection.
|
2012-02-09 09:19:58 +01:00
|
|
|
func DialUnix(net string, laddr, raddr *UnixAddr) (*UnixConn, error) {
|
2012-11-21 08:03:38 +01:00
|
|
|
return dialUnix(net, laddr, raddr, noDeadline)
|
|
|
|
}
|
|
|
|
|
|
|
|
func dialUnix(net string, laddr, raddr *UnixAddr, deadline time.Time) (*UnixConn, error) {
|
2012-12-22 02:15:33 +01:00
|
|
|
switch net {
|
|
|
|
case "unix", "unixgram", "unixpacket":
|
|
|
|
default:
|
|
|
|
return nil, UnknownNetworkError(net)
|
|
|
|
}
|
2012-11-21 08:03:38 +01:00
|
|
|
fd, err := unixSocket(net, laddr, raddr, "dial", deadline)
|
2012-02-09 09:19:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
return newUnixConn(fd), nil
|
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// UnixListener is a Unix domain socket listener. Clients should
|
|
|
|
// typically use variables of type Listener instead of assuming Unix
|
|
|
|
// domain sockets.
|
2011-09-16 17:47:21 +02:00
|
|
|
type UnixListener struct {
|
|
|
|
fd *netFD
|
|
|
|
path string
|
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// ListenUnix announces on the Unix domain socket laddr and returns a
|
2013-07-16 08:54:42 +02:00
|
|
|
// Unix listener. The network net must be "unix" or "unixpacket".
|
2012-01-25 21:56:26 +01:00
|
|
|
func ListenUnix(net string, laddr *UnixAddr) (*UnixListener, error) {
|
2012-12-22 02:15:33 +01:00
|
|
|
switch net {
|
2013-07-16 08:54:42 +02:00
|
|
|
case "unix", "unixpacket":
|
2012-12-22 02:15:33 +01:00
|
|
|
default:
|
2011-09-16 17:47:21 +02:00
|
|
|
return nil, UnknownNetworkError(net)
|
|
|
|
}
|
2012-12-22 02:15:33 +01:00
|
|
|
if laddr == nil {
|
|
|
|
return nil, &OpError{"listen", net, nil, errMissingAddress}
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
2012-11-21 08:03:38 +01:00
|
|
|
fd, err := unixSocket(net, laddr, nil, "listen", noDeadline)
|
2011-09-16 17:47:21 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2012-01-25 21:56:26 +01:00
|
|
|
err = syscall.Listen(fd.sysfd, listenerBacklog)
|
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
fd.Close()
|
2012-02-01 20:26:59 +01:00
|
|
|
return nil, &OpError{Op: "listen", Net: net, Addr: laddr, Err: err}
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
return &UnixListener{fd, laddr.Name}, nil
|
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// AcceptUnix accepts the next incoming call and returns the new
|
|
|
|
// connection and the remote address.
|
2012-02-09 09:19:58 +01:00
|
|
|
func (l *UnixListener) AcceptUnix() (*UnixConn, error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
if l == nil || l.fd == nil {
|
2012-03-02 21:01:37 +01:00
|
|
|
return nil, syscall.EINVAL
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
2012-02-09 09:19:58 +01:00
|
|
|
fd, err := l.fd.accept(sockaddrToUnix)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
2012-02-09 09:19:58 +01:00
|
|
|
c := newUnixConn(fd)
|
2011-09-16 17:47:21 +02:00
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// Accept implements the Accept method in the Listener interface; it
|
|
|
|
// waits for the next call and returns a generic Conn.
|
2011-12-03 03:17:34 +01:00
|
|
|
func (l *UnixListener) Accept() (c Conn, err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
c1, err := l.AcceptUnix()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return c1, nil
|
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// Close stops listening on the Unix address. Already accepted
|
|
|
|
// connections are not closed.
|
2011-12-03 03:17:34 +01:00
|
|
|
func (l *UnixListener) Close() error {
|
2011-09-16 17:47:21 +02:00
|
|
|
if l == nil || l.fd == nil {
|
2012-03-02 21:01:37 +01:00
|
|
|
return syscall.EINVAL
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The operating system doesn't clean up
|
|
|
|
// the file that announcing created, so
|
|
|
|
// we have to clean it up ourselves.
|
|
|
|
// There's a race here--we can't know for
|
|
|
|
// sure whether someone else has come along
|
|
|
|
// and replaced our socket name already--
|
|
|
|
// but this sequence (remove then close)
|
|
|
|
// is at least compatible with the auto-remove
|
|
|
|
// sequence in ListenUnix. It's only non-Go
|
|
|
|
// programs that can mess us up.
|
|
|
|
if l.path[0] != '@' {
|
|
|
|
syscall.Unlink(l.path)
|
|
|
|
}
|
2012-11-21 08:03:38 +01:00
|
|
|
return l.fd.Close()
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Addr returns the listener's network address.
|
|
|
|
func (l *UnixListener) Addr() Addr { return l.fd.laddr }
|
|
|
|
|
2012-01-25 22:54:22 +01:00
|
|
|
// SetDeadline sets the deadline associated with the listener.
|
|
|
|
// A zero time value disables the deadline.
|
|
|
|
func (l *UnixListener) SetDeadline(t time.Time) (err error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
if l == nil || l.fd == nil {
|
2012-03-02 21:01:37 +01:00
|
|
|
return syscall.EINVAL
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
2012-01-25 22:54:22 +01:00
|
|
|
return setDeadline(l.fd, t)
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// File returns a copy of the underlying os.File, set to blocking
|
|
|
|
// mode. It is the caller's responsibility to close f when finished.
|
2012-05-04 17:01:11 +02:00
|
|
|
// Closing l does not affect f, and closing f does not affect l.
|
2013-07-16 08:54:42 +02:00
|
|
|
//
|
|
|
|
// The returned os.File's file descriptor is different from the
|
|
|
|
// connection's. Attempting to change properties of the original
|
|
|
|
// using this duplicate may or may not have the desired effect.
|
2011-12-03 03:17:34 +01:00
|
|
|
func (l *UnixListener) File() (f *os.File, err error) { return l.fd.dup() }
|
2011-09-16 17:47:21 +02:00
|
|
|
|
2012-12-22 02:15:33 +01:00
|
|
|
// ListenUnixgram listens for incoming Unix datagram packets addressed
|
2013-07-16 08:54:42 +02:00
|
|
|
// to the local address laddr. The network net must be "unixgram".
|
|
|
|
// The returned connection's ReadFrom and WriteTo methods can be used
|
|
|
|
// to receive and send packets with per-packet addressing.
|
2012-12-22 02:15:33 +01:00
|
|
|
func ListenUnixgram(net string, laddr *UnixAddr) (*UnixConn, error) {
|
2011-09-16 17:47:21 +02:00
|
|
|
switch net {
|
|
|
|
case "unixgram":
|
|
|
|
default:
|
|
|
|
return nil, UnknownNetworkError(net)
|
|
|
|
}
|
|
|
|
if laddr == nil {
|
2012-02-01 20:26:59 +01:00
|
|
|
return nil, &OpError{"listen", net, nil, errMissingAddress}
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
2012-11-21 08:03:38 +01:00
|
|
|
fd, err := unixSocket(net, laddr, nil, "listen", noDeadline)
|
2012-02-09 09:19:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|
2012-12-22 02:15:33 +01:00
|
|
|
return newUnixConn(fd), nil
|
2011-09-16 17:47:21 +02:00
|
|
|
}
|