@@ -6,6 +6,105 @@ import (
66 "time"
77)
88
9+ type Error struct {
10+ msg string
11+ timeout , temporary bool
12+ }
13+
14+ func (ye * Error ) Error () string {
15+ return ye .msg
16+ }
17+
18+ func (ye * Error ) Timeout () bool {
19+ return ye .timeout
20+ }
21+
22+ func (ye * Error ) Temporary () bool {
23+ return ye .temporary
24+ }
25+
26+ type GoAwayError struct {
27+ Remote bool
28+ ErrorCode uint32
29+ }
30+
31+ func (e * GoAwayError ) Error () string {
32+ if e .Remote {
33+ return fmt .Sprintf ("remote sent go away, code: %d" , e .ErrorCode )
34+ }
35+ return fmt .Sprintf ("sent go away, code: %d" , e .ErrorCode )
36+ }
37+
38+ func (e * GoAwayError ) Timeout () bool {
39+ return false
40+ }
41+
42+ func (e * GoAwayError ) Temporary () bool {
43+ return false
44+ }
45+
46+ func (e * GoAwayError ) Is (target error ) bool {
47+ // to maintain compatibility with errors returned by previous versions
48+ if e .Remote && target == ErrRemoteGoAway {
49+ return true
50+ } else if ! e .Remote && target == ErrSessionShutdown {
51+ return true
52+ }
53+
54+ if err , ok := target .(* GoAwayError ); ok {
55+ return * e == * err
56+ }
57+ return false
58+ }
59+
60+ var (
61+ // ErrInvalidVersion means we received a frame with an
62+ // invalid version
63+ ErrInvalidVersion = & Error {msg : "invalid protocol version" }
64+
65+ // ErrInvalidMsgType means we received a frame with an
66+ // invalid message type
67+ ErrInvalidMsgType = & Error {msg : "invalid msg type" }
68+
69+ // ErrSessionShutdown is used if there is a shutdown during
70+ // an operation
71+ ErrSessionShutdown = & GoAwayError {ErrorCode : goAwayNormal , Remote : false }
72+
73+ // ErrStreamsExhausted is returned if we have no more
74+ // stream ids to issue
75+ ErrStreamsExhausted = & Error {msg : "streams exhausted" }
76+
77+ // ErrDuplicateStream is used if a duplicate stream is
78+ // opened inbound
79+ ErrDuplicateStream = & Error {msg : "duplicate stream initiated" }
80+
81+ // ErrReceiveWindowExceeded indicates the window was exceeded
82+ ErrRecvWindowExceeded = & Error {msg : "recv window exceeded" }
83+
84+ // ErrTimeout is used when we reach an IO deadline
85+ ErrTimeout = & Error {msg : "i/o deadline reached" , timeout : true , temporary : true }
86+
87+ // ErrStreamClosed is returned when using a closed stream
88+ ErrStreamClosed = & Error {msg : "stream closed" }
89+
90+ // ErrUnexpectedFlag is set when we get an unexpected flag
91+ ErrUnexpectedFlag = & Error {msg : "unexpected flag" }
92+
93+ // ErrRemoteGoAway is used when we get a go away from the other side
94+ ErrRemoteGoAway = & GoAwayError {Remote : true , ErrorCode : goAwayNormal }
95+
96+ // ErrStreamReset is sent if a stream is reset. This can happen
97+ // if the backlog is exceeded, or if there was a remote GoAway.
98+ ErrStreamReset = & Error {msg : "stream reset" }
99+
100+ // ErrConnectionWriteTimeout indicates that we hit the "safety valve"
101+ // timeout writing to the underlying stream connection.
102+ ErrConnectionWriteTimeout = & Error {msg : "connection write timeout" , timeout : true }
103+
104+ // ErrKeepAliveTimeout is sent if a missed keepalive caused the stream close
105+ ErrKeepAliveTimeout = & Error {msg : "keepalive timeout" , timeout : true }
106+ )
107+
9108const (
10109 // protoVersion is the only version we support
11110 protoVersion uint8 = 0
0 commit comments