在Ruby类Socket :: recv的文档中,提到了第二个选项参数“flag”,据说它是零个或多个MSG_选项。
我检查了几个不同的网站,但无法找到MSG_选项的内容。有人能指出我这些旗帜的文件吗?
答案 0 :(得分:7)
它们与C BSD套接字堆栈中的相应#define
具有相同的名称,前面的Socket::
除外。 (为了记录,回答你问的确切问题,我应该在Ruby源代码树中的ext/socket/socket.c
“中说”。所以:
>> require 'socket'
=> true
>> Socket::MSG_PEEK
=> 2
您可以通过键入man 2 recv
来查看此内容,但您可能需要先安装手册页包。还有在线手册页,请参阅:man 2 recv here。
目前,这是您需要的,这些是从NetBSD手册页中获取的Posix选项。 Linux上有更多可用的东西。在Linux上运行时,Ruby将定义其他符号,否则它们可能是未定义的,具体取决于主机。 (谢谢,mark4o。)
The flags argument to a recv call is formed by or'ing one or more of the
values:
MSG_OOB process out-of-band data
MSG_PEEK peek at incoming message
MSG_WAITALL wait for full request or error
The MSG_OOB flag requests receipt of out-of-band data that would not be
received in the normal data stream. Some protocols place expedited data
at the head of the normal data queue, and thus this flag cannot be used
with such protocols. The MSG_PEEK flag causes the receive operation to
return data from the beginning of the receive queue without removing that
data from the queue. Thus, a subsequent receive call will return the
same data. The MSG_WAITALL flag requests that the operation block until
the full request is satisfied. However, the call may still return less
data than requested if a signal is caught, an error or disconnect occurs,
or the next data to be received is of a different type than that
returned.
答案 1 :(得分:0)
我不确定,但这取决于您使用“Socket”类创建的协议。
就像,如果您将套接字创建为TCP套接字:
sock = Socket.open(Socket::PF_INET, Socket::SOCK_RAW, Socket::IPPROTO_RAW)
标志将是TCP协议的六个标志(URG,ACK,PSH等)。
我不确定,但是0对我来说非常适合。