Permalink
Browse files

domain resolved by mruby-uv

  • Loading branch information...
1 parent 9b4e032 commit 799fafeacba0d2447dc29af4fa798cbd0010e8f4 @matsumotory committed Dec 31, 2012
Showing with 10 additions and 2 deletions.
  1. +10 −2 mrblib/simplehttp.rb
View
@@ -6,7 +6,15 @@ class SimpleHttp
def initialize(address, port = DEFAULTPORT)
@uri = {}
+ ip = ""
+ UV::getaddrinfo(address, "http") do |x, info|
+ if info
+ ip = info.addr
+ end
+ end
+ UV::run()
@uri[:address] = address
+ @uri[:ip] = ip
@uri[:port] = port ? port.to_i : DEFAULTPORT
self
end
@@ -34,11 +42,10 @@ def request(method, path, req)
response_text = send_request(request_header)
SimpleHttpResponse.new(response_text)
end
-
def send_request(request_header)
socket = UV::TCP.new()
response_text = ""
- socket.connect(UV.ip4_addr(@uri[:address], @uri[:port])) do |x|
+ socket.connect(UV.ip4_addr(@uri[:ip], @uri[:port])) do |x|
if x == 0
socket.write(request_header) do |x|
socket.read_start do |b|
@@ -49,6 +56,7 @@ def send_request(request_header)
socket.close()
end
end
+
UV::run()
response_text
end

0 comments on commit 799fafe

Please sign in to comment.