Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix domain socket name in go language

Tags:

unix

go

sockets

The net package in go provides this function:

func ResolveUnixAddr(net, addr string) (*UnixAddr, error)

The string parameter net gives the network name, "unix", "unixgram" or "unixpacket".

I guess the the network name's meaning as:

  • unixgram: as type SOCK_DGRAM in socket() function, used by ListenPacket() in net package.

  • unixpacket: as type SOCK_STREAM in socket() function, used by Listen() in net package.

  • unix: either

Am I right?

like image 679
diabloneo Avatar asked Apr 09 '14 07:04

diabloneo


1 Answers

Looking at the unixSocket function in net/unixsock_posix.go, we have:

var sotype int
switch net {
case "unix":
        sotype = syscall.SOCK_STREAM
case "unixgram":
        sotype = syscall.SOCK_DGRAM
case "unixpacket":
        sotype = syscall.SOCK_SEQPACKET
default:
        return nil, UnknownNetworkError(net)
}

So you're right about unixgram being a datagram socket, but it is unix that refers to the the stream type socket and unixpacket refers to a sequential packet socket (i.e. data is sent in packets as with datagram sockets, but they are delivered in order).

like image 164
James Henstridge Avatar answered Oct 19 '22 12:10

James Henstridge