Debian Codegraph @

interface.go

raw
1 package muxado
2
3 import (
4 "github.com/inconshreveable/muxado/proto/frame"
5 "net"
6 "time"
7 )
8
9 type StreamId frame.StreamId
10 type StreamPriority frame.StreamPriority
11 type StreamType frame.StreamType
12 type ErrorCode frame.ErrorCode
13
14 // Stream is a full duplex stream-oriented connection that is multiplexed over a Session.
15 // Stream implement the net.Conn inteface.
16 type Stream interface {
17 // Write writes the bytes in the given buffer to the stream
18 Write([]byte) (int, error)
19
20 // Read reads the next bytes on the stream into the given buffer
21 Read([]byte) (int, error)
22
23 // Close closes the stream. It attempts to behave as Close does for a TCP conn in that it
24 // half-closes the stream for sending, and it will send an RST if any more data is received
25 // from the remote side.
26 Close() error
27
28 // SetDeadline sets a time after which future Read and Write operations will fail.
29 SetDeadline(time.Time) error
30
31 // SetReadDeadline sets a time after which future Read operations will fail.
32 SetReadDeadline(time.Time) error
33
34 // SetWriteDeadline sets a time after which future Write operations will fail.
35 SetWriteDeadline(time.Time) error
36
37 // HalfClose sends a data frame with a fin flag set to half-close the stream from the local side.
38 HalfClose([]byte) (int, error)
39
40 // Id returns the stream's id.
41 Id() StreamId
42
43 // StreamType returns the stream's type
44 StreamType() StreamType
45
46 // Session returns the session object this stream is running on.
47 Session() Session
48
49 // RemoteAddr returns the session transport's remote address.
50 RemoteAddr() net.Addr
51
52 // LocalAddr returns the session transport's local address.
53 LocalAddr() net.Addr
54 }
55
56 // Session multiplexes many Streams over a single underlying stream transport.
57 // Both sides of a muxado session can open new Streams. Sessions can also accept
58 // new streams from the remote side.
59 //
60 // A muxado Session implements the net.Listener interface, returning new Streams from the remote side.
61 type Session interface {
62
63 // Open initiates a new stream on the session. It is equivalent to OpenStream(0, 0, false)
64 Open() (Stream, error)
65
66 // OpenStream initiates a new stream on the session. A caller can specify a stream's priority and an opaque stream type.
67 // Setting fin to true will cause the stream to be half-closed from the local side immediately upon creation.
68 OpenStream(priority StreamPriority, streamType StreamType, fin bool) (Stream, error)
69
70 // Accept returns the next stream initiated by the remote side
71 Accept() (Stream, error)
72
73 // Kill closes the underlying transport stream immediately.
74 //
75 // You SHOULD always perfer to call Close() instead so that the connection
76 // closes cleanly by sending a GoAway frame.
77 Kill() error
78
79 // Close instructs the session to close cleanly, sending a GoAway frame if one hasn't already been sent.
80 //
81 // This implementation does not "linger". Pending writes on streams may fail.
82 //
83 // You MAY call Close() more than once. Each time after
84 // the first, Close() will return an error.
85 Close() error
86
87 // GoAway instructs the other side of the connection to stop
88 // initiating new streams by sending a GoAway frame. Most clients
89 // will just call Close(), but you may want explicit control of this
90 // in order to facilitate clean shutdowns.
91 //
92 // You MAY call GoAway() more than once. Each time after the first,
93 // GoAway() will return an error.
94 GoAway(ErrorCode, []byte) error
95
96 // LocalAddr returns the local address of the transport stream over which the session is running.
97 LocalAddr() net.Addr
98
99 // RemoteAddr returns the address of the remote side of the transport stream over which the session is running.
100 RemoteAddr() net.Addr
101
102 // Wait blocks until the session has shutdown and returns the error code for session termination. It also
103 // returns the error that caused the session to terminate as well as any debug information sent in the GoAway
104 // frame by the remote side.
105 Wait() (code ErrorCode, err error, debug []byte)
106
107 // NetListener returns an adaptor object which allows this Session to be used as a net.Listener. The returned
108 // net.Listener returns new streams initiated by the remote side as net.Conn's when calling Accept().
109 NetListener() net.Listener
110
111 // NetDial is a function that implements the same API as net.Dial and can be used in place of it. Users should keep
112 // in mind that it is the same as a call to Open(). It ignores both arguments passed to it, always initiate a new stream
113 // to the remote side.
114 NetDial(_, _ string) (net.Conn, error)
115 }