晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/opt/alt/ruby18/share/ri/1.8/system/Socket/ |
| Current File : //opt/alt/ruby18/share/ri/1.8/system/Socket/recvfrom-i.yaml |
--- !ruby/object:RI::MethodDescription
aliases: []
block_params:
comment:
- !ruby/struct:SM::Flow::P
body: Receives up to <em>maxlen</em> bytes from <tt>socket</tt>. <em>flags</em> is zero or more of the <tt>MSG_</tt> options. The first element of the results, <em>mesg</em>, is the data received. The second element, <em>sender_sockaddr</em>, contains protocol-specific information on the sender.
- !ruby/struct:SM::Flow::H
level: 3
text: Parameters
- !ruby/object:SM::Flow::LIST
contents:
- !ruby/struct:SM::Flow::LI
label: "*"
body: <tt>maxlen</tt> - the number of bytes to receive from the socket
- !ruby/struct:SM::Flow::LI
label: "*"
body: <tt>flags</tt> - zero or more of the <tt>MSG_</tt> options
type: :BULLET
- !ruby/struct:SM::Flow::H
level: 3
text: Example
- !ruby/struct:SM::Flow::VERB
body: " # In one file, start this first\n require 'socket'\n include Socket::Constants\n socket = Socket.new( AF_INET, SOCK_STREAM, 0 )\n sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )\n socket.bind( sockaddr )\n socket.listen( 5 )\n client, client_sockaddr = socket.accept\n data = client.recvfrom( 20 )[0].chomp\n puts "I only received 20 bytes '#{data}'"\n sleep 1\n socket.close\n\n # In another file, start this second\n require 'socket'\n include Socket::Constants\n socket = Socket.new( AF_INET, SOCK_STREAM, 0 )\n sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )\n socket.connect( sockaddr )\n socket.puts "Watch this get cut short!"\n socket.close\n"
- !ruby/struct:SM::Flow::H
level: 3
text: Unix-based Exceptions
- !ruby/struct:SM::Flow::P
body: "On unix-based based systems the following system exceptions may be raised if the call to <em>recvfrom</em> fails:"
- !ruby/object:SM::Flow::LIST
contents:
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EAGAIN - the <tt>socket</tt> file descriptor is marked as O_NONBLOCK and no data is waiting to be received; or MSG_OOB is set and no out-of-band data is available and either the <tt>socket</tt> file descriptor is marked as O_NONBLOCK or the <tt>socket</tt> does not support blocking to wait for out-of-band-data
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EWOULDBLOCK - see Errno::EAGAIN
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EBADF - the <tt>socket</tt> is not a valid file descriptor
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ECONNRESET - a connection was forcibly closed by a peer
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EFAULT - the socket's internal buffer, address or address length cannot be accessed or written
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EINTR - a signal interupted <em>recvfrom</em> before any data was available
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EINVAL - the MSG_OOB flag is set and no out-of-band data is available
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EIO - an i/o error occurred while reading from or writing to the filesystem
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ENOBUFS - insufficient resources were available in the system to perform the operation
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ENOMEM - insufficient memory was available to fulfill the request
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ENOSR - there were insufficient STREAMS resources available to complete the operation
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ENOTCONN - a receive is attempted on a connection-mode socket that is not connected
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ENOTSOCK - the <tt>socket</tt> does not refer to a socket
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EOPNOTSUPP - the specified flags are not supported for this socket type
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ETIMEDOUT - the connection timed out during connection establishment or due to a transmission timeout on an active connection
type: :BULLET
- !ruby/struct:SM::Flow::H
level: 3
text: Windows Exceptions
- !ruby/struct:SM::Flow::P
body: "On Windows systems the following system exceptions may be raised if the call to <em>recvfrom</em> fails:"
- !ruby/object:SM::Flow::LIST
contents:
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ENETDOWN - the network is down
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EFAULT - the internal buffer and from parameters on <tt>socket</tt> are not part of the user address space, or the internal fromlen parameter is too small to accomodate the peer address
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EINTR - the (blocking) call was cancelled by an internal call to the WinSock function WSACancelBlockingCall
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EINPROGRESS - a blocking Windows Sockets 1.1 call is in progress or the service provider is still processing a callback function
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EINVAL - <tt>socket</tt> has not been bound with a call to <em>bind</em>, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled, or (for byte stream-style sockets only) the internal len parameter on <tt>socket</tt> was zero or negative
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EISCONN - <tt>socket</tt> is already connected. The call to <em>recvfrom</em> is not permitted with a connected socket on a socket that is connetion oriented or connectionless.
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ENETRESET - the connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress.
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EOPNOTSUPP - MSG_OOB was specified, but <tt>socket</tt> is not stream-style such as type SOCK_STREAM. OOB data is not supported in the communication domain associated with <tt>socket</tt>, or <tt>socket</tt> is unidirectional and supports only send operations
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ESHUTDOWN - <tt>socket</tt> has been shutdown. It is not possible to call <em>recvfrom</em> on a socket after <em>shutdown</em> has been invoked.
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EWOULDBLOCK - <tt>socket</tt> is marked as nonblocking and a call to <em>recvfrom</em> would block.
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::EMSGSIZE - the message was too large to fit into the specified buffer and was truncated.
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ETIMEDOUT - the connection has been dropped, because of a network failure or because the system on the other end went down without notice
- !ruby/struct:SM::Flow::LI
label: "*"
body: Errno::ECONNRESET - the virtual circuit was reset by the remote side executing a hard or abortive close. The application should close the socket; it is no longer usable. On a UDP-datagram socket this error indicates a previous send operation resulted in an ICMP Port Unreachable message.
type: :BULLET
full_name: Socket#recvfrom
is_singleton: false
name: recvfrom
params: |
socket.recvfrom(maxlen) => [mesg, sender_sockaddr]
socket.recvfrom(maxlen, flags) => [mesg, sender_sockaddr]
visibility: public
|