Skip to content

Commit

Permalink
Low-level socket connection
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Jan 7, 2010
1 parent 8bbf7f9 commit bbf1bec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion lib/whois/client.rb
Expand Up @@ -14,7 +14,6 @@
#++ #++




require 'socket'
require 'timeout' require 'timeout'




Expand Down
14 changes: 9 additions & 5 deletions lib/whois/server/adapters/base.rb
Expand Up @@ -16,13 +16,15 @@


require 'whois/answer/part' require 'whois/answer/part'
require 'whois/answer' require 'whois/answer'
require 'socket'




module Whois module Whois
class Server class Server
module Adapters module Adapters


class Base class Base
include Socket::Constants


# Default Whois request port. # Default Whois request port.
DEFAULT_WHOIS_PORT = 43 DEFAULT_WHOIS_PORT = 43
Expand Down Expand Up @@ -67,7 +69,7 @@ def with_buffer(&block)
# @buffer = [] # @buffer = []
# result # result
end end

# Store an answer part in <tt>@buffer</tt>. # Store an answer part in <tt>@buffer</tt>.
def append_to_buffer(response, host) def append_to_buffer(response, host)
@buffer << ::Whois::Answer::Part.new(response, host) @buffer << ::Whois::Answer::Part.new(response, host)
Expand All @@ -80,11 +82,13 @@ def query_the_socket(qstring, host, port = nil)
private private


def ask_the_socket(qstring, host, port) def ask_the_socket(qstring, host, port)
client = TCPSocket.open(host, port) socket = Socket.new(AF_INET, SOCK_STREAM, IPPROTO_IP)
client.write("#{qstring}\r\n") # I could use put(foo) and forget the \n sockaddr = Socket.pack_sockaddr_in(port, host)
client.read # but write/read is more symmetric than puts/read socket.connect(sockaddr)
socket.write("#{qstring}\r\n") # I could use put(foo) and forget the \n
socket.read # but write/read is more symmetric than puts/read
ensure # and I really want to use read instead of gets. ensure # and I really want to use read instead of gets.
client.close if client # If != client something went wrong. socket.close if socket # If != socket something went wrong.
end end


end end
Expand Down

0 comments on commit bbf1bec

Please sign in to comment.