mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-09 23:17:35 +02:00
rpc: chunk JSON parts of communication + refactoring
JSONDecoder was buffering more of connection data than just the JSON. => Unchunker didn't bother and just started unchunking. While chaining JSONDecoder.Buffered() and the connection using ChainedReader works, it's still not a clean architecture. => Every JSON message is now wrapped in a chunked stream (chunked and unchunked) => no special-cases => Keep ChainedReader, might be useful later on...
This commit is contained in:
@ -26,7 +26,7 @@ func NewUnchunker(conn io.Reader) *Unchunker {
|
||||
func (c *Unchunker) Read(b []byte) (n int, err error) {
|
||||
|
||||
if c.finishErr != nil {
|
||||
return 0, err
|
||||
return 0, c.finishErr
|
||||
}
|
||||
|
||||
if c.remainingChunkBytes == 0 {
|
||||
@ -68,6 +68,19 @@ func (c *Unchunker) Read(b []byte) (n int, err error) {
|
||||
|
||||
}
|
||||
|
||||
func (c *Unchunker) Close() (err error) {
|
||||
|
||||
buf := make([]byte, 4096)
|
||||
for err == nil {
|
||||
_, err = c.Read(buf)
|
||||
if err == io.EOF {
|
||||
err = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
|
Reference in New Issue
Block a user