THRIFT-2278 Buffered transport doesn't support writes > buffer size

Patch: Matt Jones
This commit is contained in:
Jens Geyer 2013-12-03 22:57:59 +01:00
parent 7949447efd
commit a596038327
2 changed files with 15 additions and 6 deletions

View File

@ -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
}

View File

@ -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)
}
}