yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
blob 619e31641e4e75cfbf8244a04974fcc9c8270e10 1313 bytes (raw)
name: lib/yahns/openssl_client.rb 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
# Copyright (C) 2014, all contributors <yahns-public@yhbt.net>
# License: GPLv3 or later (see COPYING for details)

require_relative 'sendfile_compat'

# this is to be included into a Kgio::Socket-derived class
# this requires Ruby 2.1 and later for "exception: false"
module Yahns::OpenSSLClient # :nodoc:
  include Yahns::SendfileCompat

  def yahns_init_ssl(ssl_ctx)
    @need_accept = true
    @ssl = OpenSSL::SSL::SSLSocket.new(self, ssl_ctx)
  end

  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

  def kgio_syssend(buf, flags)
    kgio_trywrite(buf)
  end

  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

  def shutdown(*args)
    @ssl.shutdown(*args)
    super # BasicSocket#shutdown
  end

  def close
    @ssl.close
    super # IO#close
  end
end

debug log:

solving 619e316 ...
found 619e316 in https://yhbt.net/yahns.git/

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/yahns.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).