go语言中的Unix域套接字名称(Unix domain socket name in go language)

系统教程 行业动态 更新时间:2024-06-14 17:01:31
go语言中的Unix域套接字名称(Unix domain socket name in go language)

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

更多推荐

本文发布于:2023-04-20 16:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/a1d157cab71cb0aa56a1734c25a3b09b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   语言   Unix   language   domain

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!