Class: Puma::MiniSSL::Socket
- Inherits:
-
Object
- Object
- Puma::MiniSSL::Socket
- Defined in:
- lib/puma/minissl.rb
Instance Method Summary collapse
- #close ⇒ Object
- #engine_read_all ⇒ Object
- #flush ⇒ Object
-
#initialize(socket, engine) ⇒ Socket
constructor
A new instance of Socket.
- #peeraddr ⇒ Object
- #peercert ⇒ Object
- #read_nonblock(size) ⇒ Object
- #readpartial(size) ⇒ Object
- #to_io ⇒ Object
- #write(data) ⇒ Object (also: #syswrite, #<<)
Constructor Details
#initialize(socket, engine) ⇒ Socket
Returns a new instance of Socket.
4 5 6 7 8 |
# File 'lib/puma/minissl.rb', line 4 def initialize(socket, engine) @socket = socket @engine = engine @peercert = nil end |
Instance Method Details
#close ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/puma/minissl.rb', line 84 def close begin # Try to setup (so that we can then close them) any # partially initialized sockets. while @engine.init? # Don't let this socket hold this loop forever. # If it can't send more packets within 1s, then # give up. return unless IO.select([@socket], nil, nil, 1) begin read_nonblock(1024) rescue Errno::EAGAIN end end done = @engine.shutdown while true enc = @engine.extract @socket.write enc notify = @socket.sysread(1024) @engine.inject notify done = @engine.shutdown break if done end rescue IOError, SystemCallError # nothing ensure @socket.close end end |
#engine_read_all ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/puma/minissl.rb', line 31 def engine_read_all output = @engine.read while output and additional_output = @engine.read output << additional_output end output end |
#flush ⇒ Object
80 81 82 |
# File 'lib/puma/minissl.rb', line 80 def flush @socket.flush end |
#peeraddr ⇒ Object
119 120 121 |
# File 'lib/puma/minissl.rb', line 119 def peeraddr @socket.peeraddr end |
#peercert ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/puma/minissl.rb', line 123 def peercert return @peercert if @peercert raw = @engine.peercert return nil unless raw @peercert = OpenSSL::X509::Certificate.new raw end |
#read_nonblock(size) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/puma/minissl.rb', line 39 def read_nonblock(size) while true output = engine_read_all return output if output data = @socket.read_nonblock(size) @engine.inject(data) output = engine_read_all return output if output while neg_data = @engine.extract @socket.write neg_data end end end |
#readpartial(size) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/puma/minissl.rb', line 14 def readpartial(size) while true output = @engine.read return output if output data = @socket.readpartial(size) @engine.inject(data) output = @engine.read return output if output while neg_data = @engine.extract @socket.write neg_data end end end |
#to_io ⇒ Object
10 11 12 |
# File 'lib/puma/minissl.rb', line 10 def to_io @socket end |
#write(data) ⇒ Object Also known as: syswrite, <<
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/puma/minissl.rb', line 57 def write(data) need = data.bytesize while true wrote = @engine.write data enc = @engine.extract while enc @socket.write enc enc = @engine.extract end need -= wrote return data.bytesize if need == 0 data = data[wrote..-1] end end |