为ruby套接字定义的MSG_选项在哪里?

Sup*_*ock 9 ruby sockets

在Ruby类Socket :: recv的文档中,提到了第二个选项参数"flag",据说它是零个或多个MSG_选项.

我检查了几个不同的网站,但无法找到MSG_的选择.谁能指点我这些标志的文件?

Dig*_*oss 7

它们#define与C BSD套接字堆栈中的相应名称相同,但Socket::前面除外.(为了记录,回答你问的确切问题,我应该在Ruby源代码树中说"in ext/socket/socket.c".)所以:

>> require 'socket'
=> true
>> Socket::MSG_PEEK
=> 2
Run Code Online (Sandbox Code Playgroud)

您可以通过键入来看到这一点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.
Run Code Online (Sandbox Code Playgroud)

  • 如果您还包含发送的POSIX标志,而不仅仅是recv,那么这个答案会更好. (2认同)