mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
THRIFT-2278 Buffered transport doesn't support writes > buffer size
Patch: Matt Jones
This commit is contained in:
parent
7949447efd
commit
a596038327
@ -77,12 +77,21 @@ func (p *TBufferedTransport) Read(buf []byte) (n int, err error) {
|
||||
|
||||
func (p *TBufferedTransport) Write(buf []byte) (n int, err error) {
|
||||
wbuf := p.wbuf
|
||||
size := len(buf)
|
||||
if wbuf.pos+size > wbuf.limit { // buffer is full, flush buffer
|
||||
p.Flush()
|
||||
remaining := len(buf)
|
||||
|
||||
for remaining > 0 {
|
||||
if wbuf.pos+remaining > wbuf.limit { // buffer is full, flush buffer
|
||||
if err := p.Flush(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
copied := copy(wbuf.buffer[wbuf.pos:], buf[n:])
|
||||
|
||||
wbuf.pos += copied
|
||||
n += copied
|
||||
remaining -= copied
|
||||
}
|
||||
n = copy(wbuf.buffer[wbuf.pos:], buf)
|
||||
wbuf.pos += n
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ func (p *TFramedTransport) Flush() error {
|
||||
}
|
||||
if size > 0 {
|
||||
if n, err := p.writeBuffer.WriteTo(p.transport); err != nil {
|
||||
print("Error while flushing write buffer of size ", size, " to transport, only wrote ", n, " bytes: ", err, "\n")
|
||||
print("Error while flushing write buffer of size ", size, " to transport, only wrote ", n, " bytes: ", err.Error(), "\n")
|
||||
return NewTTransportExceptionFromError(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user