Skip to content

Commit

Permalink
Merge pull request #20 from tonistiigi/receive-eof
Browse files Browse the repository at this point in the history
receive: read stream to EOF on close
  • Loading branch information
tonistiigi authored Jan 9, 2018
2 parents 021703b + 2a21b01 commit 0b8b62d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,15 @@ func (r *receiver) run(ctx context.Context) error {
}
}
case PACKET_FIN:
return nil
for {
var p Packet
if err := r.conn.RecvMsg(&p); err != nil {
if err == io.EOF {
return nil
}
return err
}
}
}
}
})
Expand Down
12 changes: 11 additions & 1 deletion receive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"crypto/sha256"
"hash"
io "io"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -42,6 +43,7 @@ func TestCopySimple(t *testing.T) {
s1, s2 := sockPairProto(ctx)

eg.Go(func() error {
defer s1.(*fakeConnProto).closeSend()
return Send(ctx, s1, d, nil, nil)
})
eg.Go(func() error {
Expand Down Expand Up @@ -103,6 +105,7 @@ file zzz.aa
s1, s2 = sockPairProto(ctx)

eg.Go(func() error {
defer s1.(*fakeConnProto).closeSend()
return Send(ctx, s1, d, nil, nil)
})
eg.Go(func() error {
Expand Down Expand Up @@ -227,7 +230,10 @@ func (fc *fakeConnProto) RecvMsg(m interface{}) error {
select {
case <-fc.ctx.Done():
return fc.ctx.Err()
case dt := <-fc.recvChan:
case dt, ok := <-fc.recvChan:
if !ok {
return io.EOF
}
return p.Unmarshal(dt)
}
}
Expand All @@ -249,6 +255,10 @@ func (fc *fakeConnProto) SendMsg(m interface{}) error {
}
}

func (fc *fakeConnProto) closeSend() {
close(fc.sendChan)
}

type changes struct {
c map[string]ChangeKind
fn ChangeFunc
Expand Down

0 comments on commit 0b8b62d

Please sign in to comment.