Class: Puma::MiniSSL::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/puma/minissl.rb

Instance Method Summary collapse

Constructor Details

#initialize(socket, engine) ⇒ Socket

Returns a new instance of Socket



4
5
6
7
# File 'lib/puma/minissl.rb', line 4

def initialize(socket, engine)
  @socket = socket
  @engine = engine
end

Instance Method Details

#closeObject



82
83
84
# File 'lib/puma/minissl.rb', line 82

def close
  @socket.close
end

#engine_read_allObject



30
31
32
33
34
35
36
# File 'lib/puma/minissl.rb', line 30

def engine_read_all
  output = @engine.read
  while output and additional_output = @engine.read
    output << additional_output
  end
  output
end

#flushObject



78
79
80
# File 'lib/puma/minissl.rb', line 78

def flush
  @socket.flush
end

#peeraddrObject



86
87
88
# File 'lib/puma/minissl.rb', line 86

def peeraddr
  @socket.peeraddr
end

#read_nonblock(size) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/puma/minissl.rb', line 38

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puma/minissl.rb', line 13

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_ioObject



9
10
11
# File 'lib/puma/minissl.rb', line 9

def to_io
  @socket
end

#write(data) ⇒ Object Also known as: syswrite



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/puma/minissl.rb', line 56

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