-
Notifications
You must be signed in to change notification settings - Fork 8
/
net.go
56 lines (40 loc) · 1.35 KB
/
net.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
53
54
55
56
package monte
import "net"
type ConnState int
const (
StateNew ConnState = iota
StateClosed
)
type ConnStateHandler interface {
HandleConnState(conn *Conn, state ConnState)
}
type ConnStateHandlerFunc func(conn *Conn, state ConnState)
func (fn ConnStateHandlerFunc) HandleConnState(conn *Conn, state ConnState) { fn(conn, state) }
var DefaultConnStateHandler ConnStateHandlerFunc = func(conn *Conn, state ConnState) {}
type Handler interface {
HandleMessage(ctx *Context) error
}
type HandlerFunc func(ctx *Context) error
func (fn HandlerFunc) HandleMessage(ctx *Context) error { return fn(ctx) }
var DefaultHandler HandlerFunc = func(ctx *Context) error { return nil }
type Handshaker interface {
Handshake(conn net.Conn) (BufferedConn, error)
}
type HandshakerFunc func(conn net.Conn) (BufferedConn, error)
func (fn HandshakerFunc) Handshake(conn net.Conn) (BufferedConn, error) { return fn(conn) }
var DefaultClientHandshaker HandshakerFunc = func(conn net.Conn) (BufferedConn, error) {
var session Session
err := session.DoClient(conn)
if err != nil {
return nil, err
}
return NewSessionConn(session.Suite(), conn), nil
}
var DefaultServerHandshaker HandshakerFunc = func(conn net.Conn) (BufferedConn, error) {
var session Session
err := session.DoServer(conn)
if err != nil {
return nil, err
}
return NewSessionConn(session.Suite(), conn), nil
}