| Class | Thrift::FramedTransport |
| In: |
ruby/lib/thrift/transport/framed_transport.rb
|
| Parent: | BaseTransport |
# File ruby/lib/thrift/transport/framed_transport.rb, line 23
23: def initialize(transport, read=true, write=true)
24: @transport = transport
25: @rbuf = ''
26: @wbuf = ''
27: @read = read
28: @write = write
29: @index = 0
30: end
# File ruby/lib/thrift/transport/framed_transport.rb, line 40
40: def close
41: @transport.close
42: end
Writes the output buffer to the stream in the format of a 4-byte length followed by the actual data.
# File ruby/lib/thrift/transport/framed_transport.rb, line 65
65: def flush
66: return @transport.flush unless @write
67:
68: out = [@wbuf.length].pack('N')
69: out << @wbuf
70: @transport.write(out)
71: @transport.flush
72: @wbuf = ''
73: end
# File ruby/lib/thrift/transport/framed_transport.rb, line 36
36: def open
37: @transport.open
38: end
# File ruby/lib/thrift/transport/framed_transport.rb, line 32
32: def open?
33: @transport.open?
34: end
# File ruby/lib/thrift/transport/framed_transport.rb, line 44
44: def read(sz)
45: return @transport.read(sz) unless @read
46:
47: return '' if sz <= 0
48:
49: read_frame if @index >= @rbuf.length
50:
51: @index += sz
52: @rbuf.slice(@index - sz, sz) || ''
53: end
# File ruby/lib/thrift/transport/framed_transport.rb, line 55
55: def write(buf,sz=nil)
56: return @transport.write(buf) unless @write
57:
58: @wbuf << (sz ? buf[0...sz] : buf)
59: end