go中的net包提供了这个功能:
func ResolveUnixAddr(net, addr string) (*UnixAddr, error)字符串参数net给出网络名称“unix”,“unixgram”或“unixpacket”。
我猜网络名称的含义为:
unixgram :作为socket()函数中的类型SOCK_DGRAM,由网络包中的ListenPacket()使用。
unixpacket :作为socket()函数中的类型SOCK_STREAM,由NET(包)中的Listen()使用。
unix :要么
我对吗?
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?
最满意答案
查看net/unixsock_posix.go中的unixSocket函数,我们得到:
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) }所以你说unixgram是一个数据报套接字是正确的,但它是指向流类型套接字的unix ,而unixpacket指的是顺序数据包套接字(即数据与数据报套接字一样在数据包中发送,但它们按顺序传递)。
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).
更多推荐
发布评论