forked from Sandertv/go-raknet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherr.go
36 lines (32 loc) · 855 Bytes
/
err.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
package raknet
import (
"errors"
"net"
"strings"
)
var (
errBufferTooSmall = errors.New("a message sent was larger than the buffer used to receive the message into")
errListenerClosed = errors.New("use of closed listener")
)
// ErrConnectionClosed checks if the error passed was an error caused by reading from a Conn of which the
// connection was closed.
func ErrConnectionClosed(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), net.ErrClosed.Error())
}
// wrap wraps the error passed into a net.OpError with the op as operation and returns it, or nil if the error
// passed is nil.
func (conn *Conn) wrap(err error, op string) error {
if err == nil {
return nil
}
return &net.OpError{
Op: op,
Net: "raknet",
Source: conn.LocalAddr(),
Addr: conn.RemoteAddr(),
Err: err,
}
}