Class: RxIO::Client
- Inherits:
-
Object
- Object
- RxIO::Client
- Includes:
- Runify, IOBase
- Defined in:
- lib/rxio/client.rb
Overview
Client Class
Constant Summary collapse
- RECONNECT_DELAY =
Reconnect Delay (seconds)
1
- SELECT_TIMEOUT =
Select Timeout (seconds)
0.1
Constants included from IOBase
IOBase::CHUNK_SIZE, IOBase::RETRY_EXCEPTIONS
Instance Method Summary collapse
-
#initialize(addr, port, service_handler, ssl = false, ssl_params = { verify_peer: true }) ⇒ Client
constructor
Construct: Builds a Client around a given service_handler module, set to connect to addr on port.
-
#run ⇒ Object
Run: Executes the main client loop, taking care of I/O scheduling and message handling.
-
#send_msg(msg) ⇒ Object
Send Message: Enqueues a Message to be sent to the server.
-
#set_target(addr, port) ⇒ Object
Set Target: Updates the target address & port, to be used next time a connection is established.
-
#stop ⇒ Object
Stop: Requests the client loop to stop executing.
Methods included from IOBase
#drop_endpoint, #peer_error, #process_input, #read_sock, #write_sock
Constructor Details
#initialize(addr, port, service_handler, ssl = false, ssl_params = { verify_peer: true }) ⇒ Client
Construct: Builds a Client around a given service_handler module, set to connect to addr on port.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rxio/client.rb', line 38 def initialize addr, port, service_handler, ssl = false, ssl_params = { verify_peer: true } # Set SSL Context if ssl @ssl_ctx = OpenSSL::SSL::SSLContext.new @ssl_ctx.verify_mode = ssl_params[:verify_peer] ? OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT : OpenSSL::SSL::VERIFY_NONE end # Set Address & Port @addr = addr @port = port # Set Service Handler Module @service_handler = service_handler # Set Socket @sock = nil # Client Hash @client = { client: self, local: self, ibuf: '', obuf: '', lock: Mutex.new, msgs: [] } end |
Instance Method Details
#run ⇒ Object
Run: Executes the main client loop, taking care of I/O scheduling and message handling.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rxio/client.rb', line 90 def run # Update Loop begin # Update Service update until @stop rescue Exception => e puts "[!] ERROR - RxIO Client Update failed - #{e.inspect}" e.backtrace.each { |b| puts " - #{b}" } end # Drop Socket @sock.close if @sock @sock = nil end |
#send_msg(msg) ⇒ Object
Send Message: Enqueues a Message to be sent to the server.
79 80 81 82 83 84 85 86 |
# File 'lib/rxio/client.rb', line 79 def send_msg msg # Verify Implementation raise "Method send_msg is not implemented by Service Handler #{@service_handler.name}" unless @service_handler.respond_to? :send_msg # Send Message through Service Handler @service_handler.send_msg @client, msg end |
#set_target(addr, port) ⇒ Object
Set Target: Updates the target address & port, to be used next time a connection is established.
71 72 73 74 |
# File 'lib/rxio/client.rb', line 71 def set_target addr, port @addr = addr @port = port end |
#stop ⇒ Object
Stop: Requests the client loop to stop executing. The run method should return shortly after calling stop.
110 111 112 |
# File 'lib/rxio/client.rb', line 110 def stop @stop = true end |