From d52c5f9d596792009b5b2e332de116dc3fada386 Mon Sep 17 00:00:00 2001 From: cblgh Date: Mon, 9 Nov 2026 16:02:49 +0100 Subject: [PATCH] add(pipe.go): pipe.Finish to call underlying send.Finish --- examples/simple-pipe/simple-pipe.go | 2 +- pipe.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/simple-pipe/simple-pipe.go b/examples/simple-pipe/simple-pipe.go index 6144b13..5929b4f 100644 --- a/examples/simple-pipe/simple-pipe.go +++ b/examples/simple-pipe/simple-pipe.go @@ -77,7 +77,7 @@ func send(e *iroh.Endpoint, id string) { } // mark send stream as done - stream.Send().Finish() + p.Finish() exit(conn) } diff --git a/pipe.go b/pipe.go index ca6da2f..5b4249a 100644 --- a/pipe.go +++ b/pipe.go @@ -10,6 +10,7 @@ type Pipe struct { recv *RecvStream send *SendStream totalBytesRead int + finished bool } func NewPipe(stream *BiStream) *Pipe { @@ -56,6 +57,10 @@ func (p *Pipe) Read(buf []byte) (int, error) { } func (p *Pipe) Write(buf []byte) (int, error) { + if p.finished { + return 0, errors.New("Pipe.Write: Write called after Finish()") + } + n64, err := p.send.Write(buf) n := int(n64) @@ -65,3 +70,8 @@ func (p *Pipe) Write(buf []byte) (int, error) { return n, err } + +func (p *Pipe) Finish() error { + p.finished = true + return p.send.Finish() +} -- 2.54.0