解决方法
它们与C BSD套接字堆栈中的相应#defines具有相同的名称,但前面的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.