Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are MSG_ options defined for ruby sockets?

Tags:

ruby

sockets

In the documentation for Ruby class Socket::recv, there is a mention of a second option parameter "flag" which is said to be zero or more of MSG_ options.

I checked a few different sites and wasn't able to find what the MSG_ choices are. Can anyone point me to the documentation for these flags?

like image 466
Superpolock Avatar asked Oct 06 '09 20:10

Superpolock


1 Answers

They have the same names as the corresponding #defines in the C BSD socket stack, except for the Socket:: in front. (And for the record, to answer the exact question you asked, I should say "in ext/socket/socket.c" in the Ruby source tree.) So:

>> require 'socket'
=> true
>> Socket::MSG_PEEK
=> 2

You can probably see this by typing man 2 recv, though you may need to install a man pages package first. There are also online man pages, see perhaps: man 2 recv here.

For now, here is what you need, these are the Posix options taken from the NetBSD man page. There are a lot more available on Linux. When running on Linux, Ruby will define the additional symbols, otherwise they may be undefined depending on the host. (Thanks, 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.
like image 163
DigitalRoss Avatar answered Oct 24 '22 06:10

DigitalRoss