Class: Whois::Server::SocketHandler
- Inherits:
-
Object
- Object
- Whois::Server::SocketHandler
- Defined in:
- lib/whois/server/socket_handler.rb
Overview
The SocketHandler is the default query handler provided with the Whois library. It performs the WHOIS query using a synchronous socket connection.
Constant Summary collapse
- RESCUABLE_CONNECTION_ERRORS =
Array of connection errors to rescue and wrap into a ConnectionError
[ SystemCallError, SocketError, ].freeze
Instance Method Summary collapse
-
#call(query, *args) ⇒ String
Performs the Socket request.
-
#execute(query, *args) ⇒ String
private
Executes the low-level Socket connection.
Instance Method Details
#call(query, *args) ⇒ String
TODO:
*args might probably be a Hash.
Performs the Socket request.
39 40 41 42 43 |
# File 'lib/whois/server/socket_handler.rb', line 39 def call(query, *args) execute(query, *args) rescue *RESCUABLE_CONNECTION_ERRORS => e raise ConnectionError, "#{e.class}: #{e.}" end |
#execute(query, *args) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Executes the low-level Socket connection.
It opens the socket passing given args
, sends the query
and reads the response.
56 57 58 59 60 61 62 |
# File 'lib/whois/server/socket_handler.rb', line 56 def execute(query, *args) client = TCPSocket.new(*args) client.write("#{query}\r\n") # I could use put(foo) and forget the \n client.read # but write/read is more symmetric than puts/read ensure # and I really want to use read instead of gets. client&.close # If != client something went wrong. end |