src/pkg/net/unixsock.go - The Go Programming Language

Golang

Source file src/pkg/net/unixsock.go

     1	// Copyright 2009 The Go Authors.  All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	// Unix domain sockets
     6	
     7	package net
     8	
     9	// UnixAddr represents the address of a Unix domain socket end point.
    10	type UnixAddr struct {
    11		Name string
    12		Net  string
    13	}
    14	
    15	// Network returns the address's network name, "unix" or "unixgram".
    16	func (a *UnixAddr) Network() string {
    17		return a.Net
    18	}
    19	
    20	func (a *UnixAddr) String() string {
    21		if a == nil {
    22			return "<nil>"
    23		}
    24		return a.Name
    25	}
    26	
    27	func (a *UnixAddr) toAddr() Addr {
    28		if a == nil { // nil *UnixAddr
    29			return nil // nil interface
    30		}
    31		return a
    32	}
    33	
    34	// ResolveUnixAddr parses addr as a Unix domain socket address.
    35	// The string net gives the network name, "unix", "unixgram" or
    36	// "unixpacket".
    37	func ResolveUnixAddr(net, addr string) (*UnixAddr, error) {
    38		switch net {
    39		case "unix":
    40		case "unixpacket":
    41		case "unixgram":
    42		default:
    43			return nil, UnknownNetworkError(net)
    44		}
    45		return &UnixAddr{addr, net}, nil
    46	}