This repository has been archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Wondertan/fix/reset-error
Respect mux.ErrReset
- Loading branch information
Showing
6 changed files
with
108 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package sm_yamux | ||
|
||
import ( | ||
"github.com/libp2p/go-libp2p-core/mux" | ||
"github.com/libp2p/go-yamux" | ||
) | ||
|
||
// conn implements mux.MuxedConn over yamux.Session. | ||
type conn yamux.Session | ||
|
||
// Close closes underlying yamux | ||
func (c *conn) Close() error { | ||
return c.yamux().Close() | ||
} | ||
|
||
// IsClosed checks if yamux.Session is in closed state. | ||
func (c *conn) IsClosed() bool { | ||
return c.yamux().IsClosed() | ||
} | ||
|
||
// OpenStream creates a new stream. | ||
func (c *conn) OpenStream() (mux.MuxedStream, error) { | ||
s, err := c.yamux().OpenStream() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return (*stream)(s), nil | ||
} | ||
|
||
// AcceptStream accepts a stream opened by the other side. | ||
func (c *conn) AcceptStream() (mux.MuxedStream, error) { | ||
s, err := c.yamux().AcceptStream() | ||
return (*stream)(s), err | ||
} | ||
|
||
func (c *conn) yamux() *yamux.Session { | ||
return (*yamux.Session)(c) | ||
} | ||
|
||
var _ mux.MuxedConn = &conn{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
module github.com/libp2p/go-libp2p-yamux | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/libp2p/go-libp2p-core v0.3.1 | ||
github.com/libp2p/go-libp2p-testing v0.1.1 | ||
github.com/libp2p/go-yamux v1.2.4 | ||
github.com/libp2p/go-yamux v1.3.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package sm_yamux | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/libp2p/go-libp2p-core/mux" | ||
"github.com/libp2p/go-yamux" | ||
) | ||
|
||
// stream implements mux.MuxedStream over yamux.Stream. | ||
type stream yamux.Stream | ||
|
||
func (s *stream) Read(b []byte) (n int, err error) { | ||
n, err = s.yamux().Read(b) | ||
if err == yamux.ErrStreamReset { | ||
err = mux.ErrReset | ||
} | ||
|
||
return n, err | ||
} | ||
|
||
func (s *stream) Write(b []byte) (n int, err error) { | ||
n, err = s.yamux().Write(b) | ||
if err == yamux.ErrStreamReset { | ||
err = mux.ErrReset | ||
} | ||
|
||
return n, err | ||
} | ||
|
||
func (s *stream) Close() error { | ||
return s.yamux().Close() | ||
} | ||
|
||
func (s *stream) Reset() error { | ||
return s.yamux().Reset() | ||
} | ||
|
||
func (s *stream) SetDeadline(t time.Time) error { | ||
return s.yamux().SetDeadline(t) | ||
} | ||
|
||
func (s *stream) SetReadDeadline(t time.Time) error { | ||
return s.yamux().SetReadDeadline(t) | ||
} | ||
|
||
func (s *stream) SetWriteDeadline(t time.Time) error { | ||
return s.yamux().SetWriteDeadline(t) | ||
} | ||
|
||
func (s *stream) yamux() *yamux.Stream { | ||
return (*yamux.Stream)(s) | ||
} | ||
|
||
var _ mux.MuxedStream = &stream{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters