Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

WIP document Conn.Close #19

Merged
merged 3 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var NoOpHandler = func(s Stream) { s.Close() }

// Conn is a stream-multiplexing connection to a remote peer.
type Conn interface {
// Close closes the stream muxer and the the underlying net.Conn.
io.Closer

// IsClosed returns whether a connection is fully closed, so it can
Expand Down
26 changes: 26 additions & 0 deletions test/ttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"reflect"
"runtime"
"runtime/debug"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -417,6 +418,30 @@ func SubtestStreamReset(t *testing.T, tr smux.Transport) {
<-done
}

// check that Close also closes the underlying net.Conn
func SubtestWriteAfterClose(t *testing.T, tr smux.Transport) {
a, b := tcpPipe(t)

muxa, err := tr.NewConn(a, true)
checkErr(t, err)

muxb, err := tr.NewConn(b, false)
checkErr(t, err)

err = muxa.Close()
checkErr(t, err)
err = muxb.Close()
checkErr(t, err)

// make sure the underlying net.Conn was closed
if _, err := a.Write([]byte("foobar")); err == nil || !strings.Contains(err.Error(), "use of closed network connection") {
t.Fatal("write should have failed")
}
if _, err := b.Write([]byte("foobar")); err == nil || !strings.Contains(err.Error(), "use of closed network connection") {
t.Fatal("write should have failed")
}
}

func SubtestStress1Conn1Stream1Msg(t *testing.T, tr smux.Transport) {
SubtestStress(t, Options{
tr: tr,
Expand Down Expand Up @@ -487,6 +512,7 @@ func SubtestAll(t *testing.T, tr smux.Transport) {

tests := []TransportTest{
SubtestSimpleWrite,
SubtestWriteAfterClose,
SubtestStress1Conn1Stream1Msg,
SubtestStress1Conn1Stream100Msg,
SubtestStress1Conn100Stream100Msg,
Expand Down