Permalink
Browse files

Merge pull request #4 from mzp/fix_udp

Fix UDP to work
  • Loading branch information...
2 parents ca42139 + e5f990d commit 6c03bcc36cf200797ad200efe078085e3d3af4b3 @avalanche123 committed Aug 14, 2012
Showing with 15 additions and 3 deletions.
  1. +2 −2 lib/uv.rb
  2. +10 −0 lib/uv/loop.rb
  3. +3 −1 lib/uv/udp.rb
View
@@ -78,8 +78,8 @@ module UV
attach_function :udp_set_multicast_ttl, :uv_udp_set_multicast_ttl, [:uv_udp_t, :int], :int
attach_function :udp_set_broadcast, :uv_udp_set_broadcast, [:uv_udp_t, :int], :int
attach_function :udp_set_ttl, :uv_udp_set_ttl, [:uv_udp_t, :int], :int
- attach_function :udp_send, :uv_udp_send, [:uv_udp_send_t, :uv_udp_t, :uv_buf_t, :int, :sockaddr_in, :uv_udp_send_cb], :int
- attach_function :udp_send6, :uv_udp_send6, [:uv_udp_send_t, :uv_udp_t, :uv_buf_t, :int, :sockaddr_in6, :uv_udp_send_cb], :int
+ attach_function :udp_send, :uv_udp_send, [:uv_udp_send_t, :uv_udp_t, :pointer, :int, :sockaddr_in, :uv_udp_send_cb], :int
+ attach_function :udp_send6, :uv_udp_send6, [:uv_udp_send_t, :uv_udp_t, :pointer, :int, :sockaddr_in6, :uv_udp_send_cb], :int
attach_function :udp_recv_start, :uv_udp_recv_start, [:uv_udp_t, :uv_alloc_cb, :uv_udp_recv_cb], :int
attach_function :udp_recv_stop, :uv_udp_recv_stop, [:uv_udp_t], :int
View
@@ -205,6 +205,16 @@ def tcp
TCP.new(self, tcp_ptr)
end
+ # Public: Get a new UDP instance
+ #
+ # Returns UV::UDP instance
+ def udp
+ udp_ptr = UV.create_handle(:uv_udp)
+
+ check_result! UV.udp_init(@pointer, udp_ptr)
+ UV::UDP.new(self, udp_ptr)
+ end
+
# Public: Get a new TTY instance
#
# fileno - Integer file descriptor of a tty device.
View
@@ -120,7 +120,9 @@ def on_recv(handle, nread, buf, sockaddr, flags)
data = base.read_string(nread)
end
UV.free(base)
- ip, port = get_ip_and_port(sockaddr)
+ unless sockaddr.null?
+ ip, port = get_ip_and_port(UV::Sockaddr.new(sockaddr))
+ end
@recv_block.call(e, data, ip, port)
end

0 comments on commit 6c03bcc

Please sign in to comment.