Class: EventMachine::DNS::Socket
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Connection
|
|
Instance Chain:
self,
Connection
|
|
Inherits: |
EventMachine::Connection
|
Defined in: | lib/em/resolver.rb |
Class Method Summary
- .new ⇒ Socket constructor
- .open
Connection
- Inherited
.new | Override .new so subclasses don't have to call super and can ignore connection-specific arguments. |
Instance Attribute Summary
- #nameserver rw
- #nameserver=(ns) rw
Connection
- Inherited
#comm_inactivity_timeout | comm_inactivity_timeout returns the current value (float in seconds) of the inactivity-timeout property of network-connection and datagram-socket objects. |
#comm_inactivity_timeout= | Allows you to set the inactivity-timeout property for a network connection or datagram socket. |
#error? | Returns true if the connection is in an error state, false otherwise. |
#notify_readable= | Watches connection for readability. |
#notify_readable?, | |
#notify_writable= | Watches connection for writeability. |
#notify_writable? | Returns true if the connection is being watched for writability. |
#paused?, | |
#pending_connect_timeout | The duration after which a TCP connection in the connecting state will fail. |
#pending_connect_timeout= | Sets the duration after which a TCP connection in a connecting state will fail. |
#signature, #watch_only? |
Instance Method Summary
- #deregister_request(id, req)
- #post_init
-
#receive_data(data)
Decodes the packet, looks for the request and passes the response over to the requester.
- #register_request(id, req)
- #send_packet(pkt)
- #start_timer
- #stop_timer
- #tick
- #unbind
Connection
- Inherited
#associate_callback_target | conn_associate_callback_target. |
#close_connection | EventMachine::Connection#close_connection is called only by user code, and never by the event loop. |
#close_connection_after_writing | A variant of EventMachine#close_connection. |
#connection_completed | Called by the event loop when a remote TCP connection attempt completes successfully. |
#detach | Removes given connection from the event loop. |
#disable_keepalive | t_disable_keepalive. |
#enable_keepalive | t_enable_keepalive. |
#get_cipher_bits, #get_cipher_name, #get_cipher_protocol, | |
#get_idle_time | The number of seconds since the last send/receive activity on this connection. |
#get_outbound_data_size | conn_get_outbound_data_size. |
#get_peer_cert | If TLS is active on the connection, returns the remote X509 certificate as a string, in the popular PEM format. |
#get_peername | This method is used with stream-connections to obtain the identity of the remotely-connected peer. |
#get_pid | Returns the PID (kernel process identifier) of a subprocess associated with this |
#get_proxied_bytes | The number of bytes proxied to another connection. |
#get_sni_hostname, #get_sock_opt, | |
#get_sockname | Used with stream-connections to obtain the identity of the local side of the connection. |
#get_status | Returns a subprocess exit status. |
#initialize | Stubbed initialize so legacy superclasses can safely call super. |
#original_method, | |
#pause | Pause a connection so that EventMachine#send_data and #receive_data events are not fired until |
#post_init | Called by the event loop immediately after the network connection has been established, and before resumption of the network loop. |
#proxy_completed | called when the reactor finished proxying all of the requested bytes. |
#proxy_incoming_to | EventMachine::Connection#proxy_incoming_to is called only by user code. |
#proxy_target_unbound | Called by the reactor after attempting to relay incoming data to a descriptor (set as a proxy target descriptor with EventMachine.enable_proxy) that has already been closed. |
#receive_data | Called by the event loop whenever data has been received by the network connection. |
#reconnect | Reconnect to a given host/port with the current instance. |
#resume | Resume a connection's EventMachine#send_data and #receive_data events. |
#send_data | Call this method to send data to the remote end of the network connection. |
#send_datagram | Sends UDP messages. |
#send_file_data | Like Connection#send_data, this sends data to the remote end of the network connection. |
#set_sock_opt, | |
#ssl_handshake_completed | Called by |
#ssl_verify_peer | Called by |
#start_tls | Call EventMachine#start_tls at any point to initiate TLS encryption on connected streams. |
#stop_proxying | A helper method for EventMachine.disable_proxy |
#stream_file_data | Open a file on the filesystem and send it to the remote peer. |
#unbind | called by the framework whenever a connection (either a server or client connection) is closed. |
Constructor Details
.new ⇒ Socket
# File 'lib/em/resolver.rb', line 86
def initialize @nameserver = nil end
Class Method Details
.open
[ GitHub ]# File 'lib/em/resolver.rb', line 82
def self.open EventMachine::open_datagram_socket('0.0.0.0', 0, self) end
Instance Attribute Details
#nameserver (rw)
[ GitHub ]# File 'lib/em/resolver.rb', line 135
def nameserver @nameserver || Resolver.nameserver end
#nameserver=(ns) (rw)
[ GitHub ]# File 'lib/em/resolver.rb', line 131
def nameserver=(ns) @nameserver = ns end
Instance Method Details
#deregister_request(id, req)
[ GitHub ]# File 'lib/em/resolver.rb', line 122
def deregister_request(id, req) @requests.delete(id) stop_timer if @requests.length == 0 end
#post_init
[ GitHub ]# File 'lib/em/resolver.rb', line 90
def post_init @requests = {} end
#receive_data(data)
Decodes the packet, looks for the request and passes the response over to the requester
# File 'lib/em/resolver.rb', line 141
def receive_data(data) msg = nil begin msg = Resolv::DNS::Message.decode data rescue else req = @requests[msg.id] if req @requests.delete(msg.id) stop_timer if @requests.length == 0 req.receive_answer(msg) end end end
#register_request(id, req)
[ GitHub ]# File 'lib/em/resolver.rb', line 112
def register_request(id, req) if @requests.has_key?(id) raise RequestIdAlreadyUsed else @requests[id] = req end start_timer end
#send_packet(pkt)
[ GitHub ]# File 'lib/em/resolver.rb', line 127
def send_packet(pkt) send_datagram(pkt, nameserver, 53) end
#start_timer
[ GitHub ]# File 'lib/em/resolver.rb', line 94
def start_timer @timer ||= EM.add_periodic_timer(0.1, &method(:tick)) end
#stop_timer
[ GitHub ]# File 'lib/em/resolver.rb', line 98
def stop_timer EM.cancel_timer(@timer) @timer = nil end
#tick
[ GitHub ]# File 'lib/em/resolver.rb', line 106
def tick @requests.each do |id,req| req.tick end end
#unbind
[ GitHub ]# File 'lib/em/resolver.rb', line 103
def unbind end