Skip to content

Commit

Permalink
Implement CloseRead/CloseWrite
Browse files Browse the repository at this point in the history
This:

* Changes `Close` to behave like the unix `close` (sends an EOF, ignores future
inbound data).
* Adds a `CloseWrite` to replace the current `Close`.
* Adds a `CloseRead` to close the read side, while leaving the write side open.

See libp2p/go-libp2p-core#166.
  • Loading branch information
Stebalien committed Sep 2, 2020
1 parent fbda35c commit 0b57bca
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions p2p/transport/quic/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

quicproxy "github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
manet "github.com/multiformats/go-multiaddr/net"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -303,7 +303,7 @@ var _ = Describe("Connection", func() {
defer GinkgoRecover()
str, err := conn.AcceptStream()
Expect(err).ToNot(HaveOccurred())
str.Close()
str.CloseWrite()
d, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(d).To(Equal(data))
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/quic/quic_multiaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net"

ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
manet "github.com/multiformats/go-multiaddr/net"
)

var quicMA ma.Multiaddr
Expand Down
14 changes: 14 additions & 0 deletions p2p/transport/quic/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ func (s *stream) Reset() error {
return nil
}

func (s *stream) Close() error {
s.Stream.CancelRead(reset)
return s.Stream.Close()
}

func (s *stream) CloseRead() error {
s.Stream.CancelRead(reset)
return nil
}

func (s *stream) CloseWrite() error {
return s.Stream.Close()
}

var _ mux.MuxedStream = &stream{}
2 changes: 1 addition & 1 deletion p2p/transport/quic/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
quic "github.com/lucas-clemente/quic-go"
ma "github.com/multiformats/go-multiaddr"
mafmt "github.com/multiformats/go-multiaddr-fmt"
manet "github.com/multiformats/go-multiaddr-net"
manet "github.com/multiformats/go-multiaddr/net"
)

var log = logging.Logger("quic-transport")
Expand Down

0 comments on commit 0b57bca

Please sign in to comment.