forked from ipfs/kubo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
muxer.go
46 lines (35 loc) · 1.09 KB
/
muxer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package streammux
import (
"io"
"net"
)
// Stream is a bidirectional io pipe within a connection
type Stream interface {
io.Reader
io.Writer
io.Closer
}
// StreamHandler is a function that handles streams
// (usually those opened by the remote side)
type StreamHandler func(Stream)
// NoOpHandler do nothing. close streams as soon as they are opened.
var NoOpHandler = func(s Stream) { s.Close() }
// Conn is a stream-multiplexing connection to a remote peer.
type Conn interface {
io.Closer
// IsClosed returns whether a connection is fully closed, so it can
// be garbage collected.
IsClosed() bool
// OpenStream creates a new stream.
OpenStream() (Stream, error)
// AcceptStream accepts a stream opened by the other side.
AcceptStream() (Stream, error)
// Serve starts a loop, accepting incoming requests and calling
// `StreamHandler with them. (Use _instead of_ accept. not both.)
Serve(StreamHandler)
}
// Transport constructs go-stream-muxer compatible connections.
type Transport interface {
// NewConn constructs a new connection
NewConn(c net.Conn, isServer bool) (Conn, error)
}