Class: UDPSocket

Inherits:
IPSocket show all
Defined in:
lib/framework/autocomplete/UDPSocket.rb,
lib/framework/_socket.rb

Overview

It is auto-generated content. Do not do required for this file in your application.

Defined Under Namespace

Modules: WaitReadable, WaitWritable

Constant Summary collapse

SEEK_SET =
0
SEEK_CUR =
1
SEEK_END =
2
LOCK_SH =
1
LOCK_EX =
2
LOCK_UN =
8
LOCK_NB =
4
RDONLY =
0
WRONLY =
1
RDWR =
2
APPEND =
8
CREAT =
256
EXCL =
1024
NONBLOCK =
4
TRUNC =
512
BINARY =
32768
FNM_NOESCAPE =
1
FNM_PATHNAME =
2
FNM_DOTMATCH =
4
FNM_CASEFOLD =
8
FNM_SYSCASE =
8

Instance Method Summary collapse

Methods inherited from IPSocket

#addr, getaddress, #peeraddr, #recvfrom

Instance Method Details

#bind(req, req1) ⇒ Object



58
59
# File 'lib/framework/autocomplete/UDPSocket.rb', line 58

def bind(req,req1)
end

#connect(req, req1) ⇒ Object



56
57
# File 'lib/framework/autocomplete/UDPSocket.rb', line 56

def connect(req,req1)
end

#recvfrom_nonblock(rest) ⇒ Object

call-seq:

udpsocket.recvfrom_nonblock(maxlen [, flags[, outbuf [, options]]]) => [mesg, sender_inet_addr]

Receives up to maxlen bytes from udpsocket using recvfrom(2) after O_NONBLOCK is set for the underlying file descriptor. If maxlen is omitted, its default value is 65536. flags is zero or more of the MSG_ options. The first element of the results, mesg, is the data received. The second element, sender_inet_addr, is an array to represent the sender address.

When recvfrom(2) returns 0, Socket#recvfrom_nonblock returns an empty string as data. It means an empty packet.

Parameters

  • maxlen - the number of bytes to receive from the socket

  • flags - zero or more of the MSG_ options

  • outbuf - destination String buffer

  • options - keyword hash, supporting ‘exception: false`

Example

require ‘socket’ s1 = UDPSocket.new s1.bind(“127.0.0.1”, 0) s2 = UDPSocket.new s2.bind(“127.0.0.1”, 0) s2.connect(*s1.addr.values_at(3,1)) s1.connect(*s2.addr.values_at(3,1)) s1.send “aaa”, 0 begin # emulate blocking recvfrom p s2.recvfrom_nonblock(10) #=> [“aaa”, [“AF_INET”, 33302, “localhost.localdomain”, “127.0.0.1”]] rescue IO::WaitReadable IO.select() retry end

Refer to Socket#recvfrom for the exceptions that may be thrown if the call to recvfrom_nonblock fails.

UDPSocket#recvfrom_nonblock may raise any error corresponding to recvfrom(2) failure, including Errno::EWOULDBLOCK.

If the exception is Errno::EWOULDBLOCK or Errno::EAGAIN, it is extended by IO::WaitReadable. So IO::WaitReadable can be used to rescue the exceptions for retrying recvfrom_nonblock.

By specifying ‘exception: false`, the options hash allows you to indicate that recvmsg_nonblock should not raise an IO::WaitWritable exception, but return the symbol :wait_writable instead.

See

  • Socket#recvfrom



1264
1265
1266
# File 'lib/framework/_socket.rb', line 1264

def recvfrom_nonblock(len, flag = 0, outbuf = nil, exception: true)
  __recvfrom_nonblock(len, flag, outbuf, exception)
end

#send(rest) ⇒ Object



60
61
# File 'lib/framework/autocomplete/UDPSocket.rb', line 60

def send(rest)
end