Class: UV::UDP

Inherits:
Object
  • Object
show all
Includes:
Handle, Net
Defined in:
lib/uv/udp.rb

Defined Under Namespace

Modules: SocketMethods Classes: Socket4, Socket6

Instance Method Summary collapse

Methods included from Handle

#active?, close, #close, #closing?, #initialize, #ref, #unref

Methods included from Assertions

#assert_arity, #assert_block, #assert_boolean, #assert_signal, #assert_type

Methods included from Resource

#check_result, #check_result!, #to_ptr

Methods included from Listener

define_callback, undefine_callbacks

Instance Method Details

#bind(ip, port, ipv6_only = false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/uv/udp.rb', line 11

def bind(ip, port, ipv6_only = false)
  assert_type(String, ip, "ip must be a String")
  assert_type(Integer, port, "port must be an Integer")
  assert_boolean(ipv6_only, "ipv6_only must be a Boolean")

  @socket = create_socket(IPAddr.new(ip), port)
  @socket.bind(ipv6_only)

  self
end

#disable_broadcastObject



102
103
104
105
106
# File 'lib/uv/udp.rb', line 102

def disable_broadcast
  check_result! UV.udp_set_broadcast(handle, 0)

  self
end

#disable_multicast_loopObject



82
83
84
85
86
# File 'lib/uv/udp.rb', line 82

def disable_multicast_loop
  check_result! UV.udp_set_multicast_loop(handle, 0)

  self
end

#enable_broadcastObject



96
97
98
99
100
# File 'lib/uv/udp.rb', line 96

def enable_broadcast
  check_result! UV.udp_set_broadcast(handle, 1)

  self
end

#enable_multicast_loopObject



76
77
78
79
80
# File 'lib/uv/udp.rb', line 76

def enable_multicast_loop
  check_result! UV.udp_set_multicast_loop(handle, 1)

  self
end

#join(multicast_address, interface_address) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/uv/udp.rb', line 28

def join(multicast_address, interface_address)
  assert_type(String, multicast_address, "multicast_address must be a String")
  assert_type(String, interface_address, "interface_address must be a String")

  check_result! UV.udp_set_membership(handle, multicast_address, interface_address, :uv_join_group)

  self
end

#leave(multicast_address, interface_address) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/uv/udp.rb', line 37

def leave(multicast_address, interface_address)
  assert_type(String, multicast_address, "multicast_address must be a String")
  assert_type(String, interface_address, "interface_address must be a String")

  check_result! UV.udp_set_membership(handle, multicast_address, interface_address, :uv_leave_group)

  self
end

#multicast_ttl=(ttl) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/uv/udp.rb', line 88

def multicast_ttl=(ttl)
  assert_type(Integer, ttl, "ttl must be an Integer")

  check_result! UV.udp_set_multicast_ttl(handle, ttl)

  self
end

#open(fd) ⇒ Object



5
6
7
8
9
# File 'lib/uv/udp.rb', line 5

def open(fd)
  check_result! UV.udp_open(handle, fd)

  self
end

#send(ip, port, data, &block) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/uv/udp.rb', line 61

def send(ip, port, data, &block)
  assert_block(block)
  assert_arity(1, block)
  assert_type(String, ip, "ip must be a String")
  assert_type(Integer, port, "port must be an Integer")
  assert_type(String, data, "data must be a String")

  @send_block = block

  @socket = create_socket(IPAddr.new(ip), port)
  @socket.send(data, callback(:on_send))

  self
end

#socknameObject



22
23
24
25
26
# File 'lib/uv/udp.rb', line 22

def sockname
  sockaddr, len = get_sockaddr_and_len
  check_result! UV.udp_getsockname(handle, sockaddr, len)
  get_ip_and_port(UV::Sockaddr.new(sockaddr), len.get_int(0))
end

#start_recv(&block) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/uv/udp.rb', line 46

def start_recv(&block)
  assert_block(block)
  assert_arity(4, block)

  @recv_block = block

  check_result! UV.udp_recv_start(handle, callback(:on_allocate), callback(:on_recv))

  self
end

#stop_recvObject



57
58
59
# File 'lib/uv/udp.rb', line 57

def stop_recv
  check_result! UV.udp_recv_stop(handle)
end

#ttl=(ttl) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/uv/udp.rb', line 108

def ttl=(ttl)
  assert_type(Integer, ttl, "ttl must be an Integer")

  check_result! UV.udp_set_ttl(handle, Integer(ttl))

  self
end