在Ruby类Socket::recv的文档中,提到了第二个选项参数“标志”,该参数被称为MSG_选项的零个或多个。

我检查了几个不同的站点,但找不到MSG_的选择。谁能指出我有关这些标志的文档?

最佳答案

它们具有与C BSD套接字堆栈中相应的#define相同的名称,除了前面的Socket::之外。 (根据记录,为回答您提出的确切问题,我应该在Ruby源代码树中说“in 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.

关于ruby - ruby socket 在哪里定义了MSG_选项?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1527895/

10-14 17:50
查看更多