gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 06:50:18 26 4
gpt4 key购买 nike

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

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

最佳答案

除了前面的Socket:: 之外,它们与C BSD 套接字堆栈中相应的#define 同名。 (作为记录,为了回答您提出的确切问题,我应该在 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​​ 套接字定义的 MSG_ 选项在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1527895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com