Module: Buffering
- Includes:
- Enumerable
- Included in:
- OpenSSL::SSL::SSLSocket
- Defined in:
- lib/openssl/buffering.rb
Overview
$RCSfile$ -- Buffering mix-in module.
Info
'OpenSSL for Ruby 2' project
Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org>
All rights reserved.
Licence
This program is licenced under the same licence as Ruby.
(See the file 'LICENCE'.)
Version
$Id: buffering.rb 13706 2007-10-15 08:29:08Z usa $
Constant Summary
- BLOCK_SIZE =
1024*16
Instance Attribute Summary (collapse)
-
- (Object) sync
Returns the value of attribute sync.
Instance Method Summary (collapse)
- - (Object) <<(s)
- - (Object) close
- - (Object) each(eol = $/) (also: #each_line)
- - (Object) each_byte
- - (Boolean) eof? (also: #eof)
- - (Object) flush
- - (Object) getc
- - (Object) gets(eol = $/)
-
- (Buffering) initialize(*args)
A new instance of Buffering.
- - (Object) print(*args)
- - (Object) printf(s, *args)
- - (Object) puts(*args)
- - (Object) read(size = nil, buf = nil)
- - (Object) readchar
- - (Object) readline(eol = $/)
- - (Object) readlines(eol = $/)
- - (Object) readpartial(maxlen, buf = nil)
- - (Object) ungetc(c)
- - (Object) write(s)
Instance Attribute Details
- (Object) sync
Returns the value of attribute sync
19 20 21 |
# File 'lib/openssl/buffering.rb', line 19 def sync @sync end |
Instance Method Details
- (Object) <<(s)
196 197 198 199 |
# File 'lib/openssl/buffering.rb', line 196 def << (s) do_write(s) self end |
- (Object) close
235 236 237 238 |
# File 'lib/openssl/buffering.rb', line 235 def close flush rescue nil sysclose end |
- (Object) each(eol = $/) Also known as: each_line
117 118 119 120 121 |
# File 'lib/openssl/buffering.rb', line 117 def each(eol=$/) while line = self.gets(eol) yield line end end |
- (Object) each_byte
142 143 144 145 146 |
# File 'lib/openssl/buffering.rb', line 142 def each_byte while c = getc yield(c) end end |
- (Boolean) eof? Also known as: eof
157 158 159 160 |
# File 'lib/openssl/buffering.rb', line 157 def eof? fill_rbuff if !@eof && @rbuffer.empty? @eof && @rbuffer.empty? end |
- (Object) flush
228 229 230 231 232 233 |
# File 'lib/openssl/buffering.rb', line 228 def flush osync = @sync @sync = true do_write "" @sync = osync end |
- (Object) getc
137 138 139 140 |
# File 'lib/openssl/buffering.rb', line 137 def getc c = read(1) c ? c[0] : nil end |
- (Object) gets(eol = $/)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/openssl/buffering.rb', line 102 def gets(eol=$/) idx = @rbuffer.index(eol) until @eof break if idx fill_rbuff idx = @rbuffer.index(eol) end if eol.is_a?(Regexp) size = idx ? idx+$&.size : nil else size = idx ? idx+eol.size : nil end consume_rbuff(size) end |
- (Buffering) initialize(*args)
A new instance of Buffering
22 23 24 25 26 |
# File 'lib/openssl/buffering.rb', line 22 def initialize(*args) @eof = false @rbuffer = "" @sync = @io.sync end |
- (Object) print(*args)
216 217 218 219 220 221 |
# File 'lib/openssl/buffering.rb', line 216 def print(*args) s = "" args.each{ |arg| s << arg.to_s } do_write(s) nil end |
- (Object) printf(s, *args)
223 224 225 226 |
# File 'lib/openssl/buffering.rb', line 223 def printf(s, *args) do_write(s % args) nil end |
- (Object) puts(*args)
201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/openssl/buffering.rb', line 201 def puts(*args) s = "" if args.empty? s << "\n" end args.each{|arg| s << arg.to_s if $/ && /\n\z/ !~ s s << "\n" end } do_write(s) nil end |
- (Object) read(size = nil, buf = nil)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/openssl/buffering.rb', line 56 def read(size=nil, buf=nil) if size == 0 if buf buf.clear else buf = "" end return @eof ? nil : buf end until @eof break if size && size <= @rbuffer.size fill_rbuff end ret = consume_rbuff(size) || "" if buf buf.replace(ret) ret = buf end (size && ret.empty?) ? nil : ret end |
- (Object) readchar
148 149 150 151 |
# File 'lib/openssl/buffering.rb', line 148 def readchar raise EOFError if eof? getc end |
- (Object) readline(eol = $/)
132 133 134 135 |
# File 'lib/openssl/buffering.rb', line 132 def readline(eol=$/) raise EOFError if eof? gets(eol) end |
- (Object) readlines(eol = $/)
124 125 126 127 128 129 130 |
# File 'lib/openssl/buffering.rb', line 124 def readlines(eol=$/) ary = [] while line = self.gets(eol) ary << line end ary end |
- (Object) readpartial(maxlen, buf = nil)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/openssl/buffering.rb', line 77 def readpartial(maxlen, buf=nil) if maxlen == 0 if buf buf.clear else buf = "" end return @eof ? nil : buf end if @rbuffer.empty? begin return sysread(maxlen, buf) rescue Errno::EAGAIN retry end end ret = consume_rbuff(maxlen) if buf buf.replace(ret) ret = buf end raise EOFError if ret.empty? ret end |
- (Object) ungetc(c)
153 154 155 |
# File 'lib/openssl/buffering.rb', line 153 def ungetc(c) @rbuffer[0,0] = c.chr end |
- (Object) write(s)
191 192 193 194 |
# File 'lib/openssl/buffering.rb', line 191 def write(s) do_write(s) s.length end |