Skip to content

Commit

Permalink
add CloseRead/CloseWrite on streams (#166)
Browse files Browse the repository at this point in the history
* add CloseRead/CloseWrite on streams

This changes the behavior of `Close` to behave as one would expect: it closes
the stream. The new methods, CloseWrite/CloseRead allow for closing the stream in
a single direction.

Note: This _does not_ implement CancelWrite/CancelRead as our stream muxer
_protocols_ don't support that.

fixes #9

* remove stream util helpers

FullClose and AwaitEOF were introduced to work around the fact that calling
Close on a stream only closed the write half. All users must adapt their code
to the new interfaces, so this change is intentionally breaking.
  • Loading branch information
Stebalien authored Sep 2, 2020
1 parent 1f8b03e commit ef2b995
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 209 deletions.
56 changes: 0 additions & 56 deletions core/helpers/stream.go

This file was deleted.

151 changes: 0 additions & 151 deletions core/helpers/stream_test.go

This file was deleted.

24 changes: 22 additions & 2 deletions core/mux/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,30 @@ type MuxedStream interface {
io.Reader
io.Writer

// Close closes the stream for writing. Reading will still work (that
// is, the remote side can still write).
// Close closes the stream.
//
// * Any buffered data for writing will be flushed.
// * Future reads will fail.
// * Any in-progress reads/writes will be interrupted.
//
// Close may be asynchronous and _does not_ guarantee receipt of the
// data.
io.Closer

// CloseWrite closes the stream for writing but leaves it open for
// reading.
//
// CloseWrite does not free the stream, users must still call Close or
// Reset.
CloseWrite() error

// CloseRead closes the stream for writing but leaves it open for
// reading.
//
// CloseRead does not free the stream, users must still call Close or
// Reset.
CloseRead() error

// Reset closes both ends of the stream. Use this to tell the remote
// side to hang up and go away.
Reset() error
Expand Down

0 comments on commit ef2b995

Please sign in to comment.