-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtransport.go
48 lines (38 loc) · 1.03 KB
/
transport.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
package l3
import (
"io"
"strconv"
)
// Transport represents a communicate channel to send and receive TLV packets.
type Transport interface {
io.ReadWriteCloser
// MTU returns maximum size of outgoing packets.
MTU() int
// State returns current state.
State() TransportState
// OnStateChange registers a callback to be invoked when State() changes.
// Returns a function to cancel the callback registration.
OnStateChange(cb func(st TransportState)) (cancel func())
}
// TransportState indicates up/down state of a transport.
type TransportState int
const (
// TransportUp indicates the transport is operational.
TransportUp TransportState = iota
// TransportDown indicates the transport is nonoperational.
TransportDown
// TransportClosed indicates the transport has been closed.
// It cannot be restarted.
TransportClosed
)
func (st TransportState) String() string {
switch st {
case TransportUp:
return "up"
case TransportDown:
return "down"
case TransportClosed:
return "closed"
}
return strconv.Itoa(int(st))
}