5

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?

1 Answer 1

10

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).

Sign up to request clarification or add additional context in comments.

2 Comments

I find question for SOCK_SEQPACKET.
Think of SEQPACKET like STREAM, but each recv operation on the socket will correspond to a send from the other end. That is, the write boundaries will be maintained when read by the other party.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.