-
Notifications
You must be signed in to change notification settings - Fork 0
/
iohandler.go
88 lines (67 loc) · 1.66 KB
/
iohandler.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// File IoHandler
// @Author: [email protected]
// @Date: 2016-08-23
package gonetio
type BaseObject interface {
}
type IoHandler interface {
// Connection opened
// The event fired when the server accept a new connection
// or the client client server
ConnOpened(*IoFilter)
// Connection closed
ConnClosed(*IoFilter)
// The event fired when receive message from the connection
MessageReceived(con *IoFilter, obj BaseObject)
// Fire Write
FireWrite(con *IoFilter, obj BaseObject)
// is in bound handler
IsInBound() bool
// is out bound handler
IsOutBound() bool
// Clone
Clone() IoHandler
}
var (
InBound = 1
OutBound = 2
)
type IoHandlerImp struct {
boundType int // in or out bound type
}
// new handler
func newHandler(bType int) *IoHandlerImp {
return &IoHandlerImp{
boundType: bType,
}
}
// Connection opened
// The event fired when the server accept a new connection
// or the client client server
func (this *IoHandlerImp) ConnOpened(*IoFilter) {
}
// Connection closed
func (this *IoHandlerImp) ConnClosed(*IoFilter) {
}
// The event fired when receive message from the connection
func (this *IoHandlerImp) MessageReceived(filter *IoFilter, obj BaseObject) {
}
// Fire Write
func (this *IoHandlerImp) FireWrite(filter *IoFilter, obj BaseObject) {
}
// is in bound handler
func (this *IoHandlerImp) IsInBound() bool {
return this.boundType&InBound != 0
}
// is out bound handler
func (this *IoHandlerImp) IsOutBound() bool {
return this.boundType&OutBound != 0
}
// Clone
func (this *IoHandlerImp) Clone() IoHandler {
return newHandler(InBound)
}
// set bound type
func (this *IoHandlerImp) SetBoundType(bType int) {
this.boundType = bType
}