forked from hzane/enet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
enetapi.go
33 lines (27 loc) · 950 Bytes
/
enetapi.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
package enet
import (
"os"
)
type PeerEventHandler func(host Host, endpoint string, ret int)
// chanid == 0xff unreliable data
type DataEventHandler func(host Host, endpoint string, chanid uint8, payload []byte)
type AckEventHandler func(host Host, endpoint string, chanid uint8, payload []byte)
// push a signal to chan os.Signal will make host quit run loop
type Host interface {
SetConnectionHandler(PeerEventHandler)
SetDisconnectionHandler(PeerEventHandler)
SetDataHandler(DataEventHandler)
SetAckHandler(AckEventHandler)
Connect(endpoint string)
Disconnect(endpoint string)
Write(endpoint string, chanid uint8, dat []byte, customHeader *EnetPacketHeader)
Run(chan os.Signal)
Stop()
}
// func NewHost(addr string) (Host, error)
/*
type Peer interface {
Disconnect() // must be called in host-run routine
Write(chanid uint8, dat []byte) // be carefull, must be called in host-run routine
Addr() net.Addr
}*/