Module: Yahns::OpenSSLClient
- Includes:
- SendfileCompat
- Defined in:
- lib/yahns/openssl_client.rb
Overview
this is to be included into a Kgio::Socket-derived class this requires Ruby 2.1 and later for “exception: false”
Instance Method Summary collapse
- #close ⇒ Object
- #kgio_syssend(buf, flags) ⇒ Object
- #kgio_tryread(len, buf) ⇒ Object
- #kgio_trywrite(buf) ⇒ Object
- #shutdown(*args) ⇒ Object
- #yahns_init_ssl(ssl_ctx) ⇒ Object
Methods included from SendfileCompat
Instance Method Details
#close ⇒ Object
50 51 52 53 |
# File 'lib/yahns/openssl_client.rb', line 50 def close @ssl.close super # IO#close end |
#kgio_syssend(buf, flags) ⇒ Object
23 24 25 |
# File 'lib/yahns/openssl_client.rb', line 23 def kgio_syssend(buf, flags) kgio_trywrite(buf) end |
#kgio_tryread(len, buf) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/yahns/openssl_client.rb', line 27 def kgio_tryread(len, buf) if @need_accept # most protocols require read before write, so we start the negotiation # process here: begin @ssl.accept_nonblock rescue IO::WaitReadable return :wait_readable rescue IO::WaitWritable return :wait_writable rescue OpenSSL::SSL::SSLError return nil end @need_accept = false end @ssl.read_nonblock(len, buf, exception: false) end |
#kgio_trywrite(buf) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/yahns/openssl_client.rb', line 16 def kgio_trywrite(buf) rv = @ssl.write_nonblock(buf, exception: false) Integer === rv and rv = buf.bytesize == rv ? nil : buf.byteslice(rv, buf.bytesize) rv end |
#shutdown(*args) ⇒ Object
45 46 47 48 |
# File 'lib/yahns/openssl_client.rb', line 45 def shutdown(*args) @ssl.shutdown(*args) super # BasicSocket#shutdown end |
#yahns_init_ssl(ssl_ctx) ⇒ Object
11 12 13 14 |
# File 'lib/yahns/openssl_client.rb', line 11 def yahns_init_ssl(ssl_ctx) @need_accept = true @ssl = OpenSSL::SSL::SSLSocket.new(self, ssl_ctx) end |