-
Notifications
You must be signed in to change notification settings - Fork 5
/
connection.go
52 lines (37 loc) · 923 Bytes
/
connection.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
47
48
49
50
51
52
package evnio
import (
"bytes"
"context"
"errors"
"net"
"sync"
)
var ErrConnectionClosed = errors.New("connection closed")
const (
ConnectFdContextKey = "connect-fd-context-key"
)
type Connection interface {
UniqID() uint64
RemoteAddr() net.Addr
LocalAddr() net.Addr
Context() context.Context
SetContext(context.Context)
Send([]byte, Action) error
Close() error
}
type ConnectionHandler interface {
OnOpen(c Connection)
OnMessage(c Connection, data []byte)
OnClose(c Connection)
}
type defaultConnectionHandler struct{}
func (*defaultConnectionHandler) OnOpen(c Connection) {}
func (*defaultConnectionHandler) OnMessage(c Connection, data []byte) {}
func (*defaultConnectionHandler) OnClose(c Connection) {}
var connBufferPool = NewBufferPoll()
func NewBufferPoll() (pool sync.Pool) {
pool.New = func() interface{} {
return &bytes.Buffer{}
}
return pool
}