Class: Net::BufferedIO
- Inherits:
-
Object
show all
- Defined in:
- lib/net/protocol.rb
Overview
:nodoc: internal use only
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(io, read_timeout: 60, write_timeout: 60, continue_timeout: nil, debug_output: nil) ⇒ BufferedIO
Returns a new instance of BufferedIO.
114
115
116
117
118
119
120
121
|
# File 'lib/net/protocol.rb', line 114
def initialize(io, read_timeout: 60, write_timeout: 60, continue_timeout: nil, debug_output: nil)
@io = io
@read_timeout = read_timeout
@write_timeout = write_timeout
@continue_timeout = continue_timeout
@debug_output = debug_output
@rbuf = ''.b
end
|
Instance Attribute Details
#continue_timeout ⇒ Object
Returns the value of attribute continue_timeout
126
127
128
|
# File 'lib/net/protocol.rb', line 126
def continue_timeout
@continue_timeout
end
|
#debug_output ⇒ Object
Returns the value of attribute debug_output
127
128
129
|
# File 'lib/net/protocol.rb', line 127
def debug_output
@debug_output
end
|
#io ⇒ Object
Returns the value of attribute io
123
124
125
|
# File 'lib/net/protocol.rb', line 123
def io
@io
end
|
#read_timeout ⇒ Object
Returns the value of attribute read_timeout
124
125
126
|
# File 'lib/net/protocol.rb', line 124
def read_timeout
@read_timeout
end
|
#write_timeout ⇒ Object
Returns the value of attribute write_timeout
125
126
127
|
# File 'lib/net/protocol.rb', line 125
def write_timeout
@write_timeout
end
|
Instance Method Details
#close ⇒ Object
141
142
143
|
# File 'lib/net/protocol.rb', line 141
def close
@io.close
end
|
#closed? ⇒ Boolean
137
138
139
|
# File 'lib/net/protocol.rb', line 137
def closed?
@io.closed?
end
|
#eof? ⇒ Boolean
133
134
135
|
# File 'lib/net/protocol.rb', line 133
def eof?
@io.eof?
end
|
#inspect ⇒ Object
129
130
131
|
# File 'lib/net/protocol.rb', line 129
def inspect
"#<#{self.class} io=#{@io}>"
end
|
#read(len, dest = ''.b, ignore_eof = false) ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/net/protocol.rb', line 151
def read(len, dest = ''.b, ignore_eof = false)
LOG "reading #{len} bytes..."
read_bytes = 0
begin
while read_bytes + @rbuf.size < len
s = rbuf_consume(@rbuf.size)
read_bytes += s.size
dest << s
rbuf_fill
end
s = rbuf_consume(len - read_bytes)
read_bytes += s.size
dest << s
rescue EOFError
raise unless ignore_eof
end
LOG "read #{read_bytes} bytes"
dest
end
|
#read_all(dest = ''.b) ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/net/protocol.rb', line 171
def read_all(dest = ''.b)
LOG 'reading all...'
read_bytes = 0
begin
while true
s = rbuf_consume(@rbuf.size)
read_bytes += s.size
dest << s
rbuf_fill
end
rescue EOFError
;
end
LOG "read #{read_bytes} bytes"
dest
end
|
#readline ⇒ Object
200
201
202
|
# File 'lib/net/protocol.rb', line 200
def readline
readuntil("\n").chop
end
|
#readuntil(terminator, ignore_eof = false) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/net/protocol.rb', line 188
def readuntil(terminator, ignore_eof = false)
begin
until idx = @rbuf.index(terminator)
rbuf_fill
end
return rbuf_consume(idx + terminator.size)
rescue EOFError
raise unless ignore_eof
return rbuf_consume(@rbuf.size)
end
end
|
#write(*strs) ⇒ Object
Also known as:
<<
246
247
248
249
250
|
# File 'lib/net/protocol.rb', line 246
def write(*strs)
writing {
write0(*strs)
}
end
|
#writeline(str) ⇒ Object
254
255
256
257
258
|
# File 'lib/net/protocol.rb', line 254
def writeline(str)
writing {
write0 str + "\r\n"
}
end
|