The Go Programming Language

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	import (
    10		"os"
    11	)
    12	
    13	// UnixAddr represents the address of a Unix domain socket end point.
    14	type UnixAddr struct {
    15		Name string
    16		Net  string
    17	}
    18	
    19	// Network returns the address's network name, "unix" or "unixgram".
    20	func (a *UnixAddr) Network() string {
    21		return a.Net
    22	}
    23	
    24	func (a *UnixAddr) String() string {
    25		if a == nil {
    26			return "<nil>"
    27		}
    28		return a.Name
    29	}
    30	
    31	func (a *UnixAddr) toAddr() Addr {
    32		if a == nil { // nil *UnixAddr
    33			return nil // nil interface
    34		}
    35		return a
    36	}
    37	
    38	// ResolveUnixAddr parses addr as a Unix domain socket address.
    39	// The string net gives the network name, "unix", "unixgram" or
    40	// "unixpacket".
    41	func ResolveUnixAddr(net, addr string) (*UnixAddr, os.Error) {
    42		switch net {
    43		case "unix":
    44		case "unixpacket":
    45		case "unixgram":
    46		default:
    47			return nil, UnknownNetworkError(net)
    48		}
    49		return &UnixAddr{addr, net}, nil
    50	}

release.r60.3. Except as noted, this content is licensed under a Creative Commons Attribution 3.0 License.