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.
116
117
118
119
120
121
122
123
|
# File 'lib/net/protocol.rb', line 116
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.
128
129
130
|
# File 'lib/net/protocol.rb', line 128
def continue_timeout
@continue_timeout
end
|
#debug_output ⇒ Object
Returns the value of attribute debug_output.
129
130
131
|
# File 'lib/net/protocol.rb', line 129
def debug_output
@debug_output
end
|
#io ⇒ Object
Returns the value of attribute io.
125
126
127
|
# File 'lib/net/protocol.rb', line 125
def io
@io
end
|
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
126
127
128
|
# File 'lib/net/protocol.rb', line 126
def read_timeout
@read_timeout
end
|
#write_timeout ⇒ Object
Returns the value of attribute write_timeout.
127
128
129
|
# File 'lib/net/protocol.rb', line 127
def write_timeout
@write_timeout
end
|
Instance Method Details
#close ⇒ Object
143
144
145
|
# File 'lib/net/protocol.rb', line 143
def close
@io.close
end
|
#closed? ⇒ Boolean
139
140
141
|
# File 'lib/net/protocol.rb', line 139
def closed?
@io.closed?
end
|
#eof? ⇒ Boolean
135
136
137
|
# File 'lib/net/protocol.rb', line 135
def eof?
@io.eof?
end
|
#inspect ⇒ Object
131
132
133
|
# File 'lib/net/protocol.rb', line 131
def inspect
"#<#{self.class} io=#{@io}>"
end
|
#read(len, dest = ''.b, ignore_eof = false) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/net/protocol.rb', line 153
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/net/protocol.rb', line 173
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
202
203
204
|
# File 'lib/net/protocol.rb', line 202
def readline
readuntil("\n").chop
end
|
#readuntil(terminator, ignore_eof = false) ⇒ Object
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/net/protocol.rb', line 190
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:
<<
248
249
250
251
252
|
# File 'lib/net/protocol.rb', line 248
def write(*strs)
writing {
write0(*strs)
}
end
|
#writeline(str) ⇒ Object
256
257
258
259
260
|
# File 'lib/net/protocol.rb', line 256
def writeline(str)
writing {
write0 str + "\r\n"
}
end
|