Skip to content

Commit

Permalink
domain resolved by mruby-uv
Browse files Browse the repository at this point in the history
  • Loading branch information
matsumotory committed Dec 31, 2012
1 parent 9b4e032 commit 799fafe
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mrblib/simplehttp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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|
Expand All @@ -49,6 +56,7 @@ def send_request(request_header)
socket.close()
end
end

UV::run()
response_text
end
Expand Down

0 comments on commit 799fafe

Please sign in to comment.