Class: InternetHakai::RevSslClient

Inherits:
RevHttpClient show all
Includes:
Rev::SSL
Defined in:
lib/internethakai/hakairev/http_client.rb

Instance Attribute Summary

Attributes inherited from RevHttpClient

#client_queue, #complete, #result, #tfactory, #timeout, #useragent

Attributes inherited from RevHttpConnection

#busy, #connected

Instance Method Summary collapse

Methods inherited from RevHttpClient

create, #handle_timeout, #has_callback, #on_error, #on_request_complete, #prepare, #release, #request_send, #send_request_header, #set_callback, #set_cookie, #set_header, #set_headers

Methods inherited from RevHttpConnection

#attach, #attached?, #close, #free, #init, #initialize, #insertcache, #on_body_data, #on_connect_failed, #on_error, #on_failure, #on_read, #on_request_complete, #on_resolve_failed, #searchcache, #send_request, #to_response_object

Methods inherited from Rev::HttpClient

#failedtrue

Constructor Details

This class inherits a constructor from InternetHakai::RevHttpConnection

Instance Method Details

#on_connectObject



414
415
416
417
418
419
420
# File 'lib/internethakai/hakairev/http_client.rb', line 414

def on_connect
    unless @__ssl_inited
        ssl_client_start
        @__ssl_inited = true
    end
    super
end

#on_readableObject



405
406
407
408
409
410
411
412
413
# File 'lib/internethakai/hakairev/http_client.rb', line 405

def on_readable
    begin
        on_read @_ssl_socket.read_nonblock(Rev::IO::INPUT_SIZE)
    rescue Errno::EAGAIN, Rev::SSL::IO::ReadAgain
        return
    rescue OpenSSL::SSL::SSLError, Errno::EPIPE, Errno::ECONNRESET, EOFError
        close
    end
end

#on_writableObject



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/internethakai/hakairev/http_client.rb', line 389

def on_writable
    begin
        nbytes = @_ssl_socket.write_nonblock @_write_buffer.to_str
    rescue Errno::EAGAIN, Rev::SSL::IO::WriteAgain, Rev::SSL::IO::ReadAgain
        return
    rescue OpenSSL::SSL::SSLError, Errno::EPIPE, Errno::ECONNRESET
        close
        return
    end
    @_write_buffer.read(nbytes)

    if @_write_buffer.empty?
        disable_write_watcher
        on_write_complete
    end
end

#reconnectObject



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/internethakai/hakairev/http_client.rb', line 365

def reconnect
    super
    context = respond_to?(:ssl_context) ? ssl_context : OpenSSL::SSL::SSLContext.new

    @_ssl_socket = Rev::SSL::IO.new(@_io, context)
    @_ssl_init = proc { @_ssl_socket.connect_nonblock }
    @__ssl_inited = true

    begin
        @_ssl_init.call
        ssl_init_complete
    rescue Rev::SSL::IO::ReadAgain
        return
    rescue Rev::SSL::IO::WriteAgain
        return
    rescue OpenSSL::SSL::SSLError, Errno::ECONNRESET, Errno::EPIPE
        close
    rescue => ex
        if respond_to? :on_ssl_error
            on_ssl_error(ex)
        else raise ex
        end
    end
end