2023-07-28 10:30:38 +08:00
|
|
|
package dynamics
|
|
|
|
|
|
|
|
import (
|
2023-07-28 14:22:54 +08:00
|
|
|
"encoding/hex"
|
|
|
|
"github.com/panjf2000/gnet/v2"
|
|
|
|
"io"
|
2023-07-28 10:30:38 +08:00
|
|
|
"joylink.club/bj-rtsts-server/config"
|
2023-07-28 14:22:54 +08:00
|
|
|
"net"
|
|
|
|
"runtime"
|
2023-07-28 10:30:38 +08:00
|
|
|
"testing"
|
2023-07-28 14:22:54 +08:00
|
|
|
"time"
|
2023-07-28 10:30:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRunUdpServer(t *testing.T) {
|
|
|
|
config.LoadConfig()
|
|
|
|
RegisterTrainInfoHandler(&ExampleTrainInfoHandler{})
|
|
|
|
RunUdpServer()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSendTurnoutInfo(t *testing.T) {
|
|
|
|
config.LoadConfig()
|
|
|
|
SendTurnoutInfo(&TurnoutInfo{
|
|
|
|
Code: 2,
|
|
|
|
NPosition: true,
|
|
|
|
RPosition: false,
|
|
|
|
})
|
|
|
|
}
|
2023-07-28 14:22:54 +08:00
|
|
|
|
|
|
|
func BenchmarkUdpServer_OnTraffic(b *testing.B) {
|
|
|
|
runtime.GOMAXPROCS(1) //1个协程
|
|
|
|
buf, _ := hex.DecodeString("0009012EE009000000070380000006000100020003000A000A000A000A000A000A000A")
|
|
|
|
// 创建 udpServer 对象
|
|
|
|
server := &udpServer{}
|
|
|
|
// 创建虚拟的 gnet.Conn 对象
|
|
|
|
conn := &virtualConn{
|
|
|
|
readBuffer: buf,
|
|
|
|
}
|
|
|
|
|
|
|
|
// 在 Benchmark 中运行测试
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
server.OnTraffic(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type virtualConn struct {
|
|
|
|
readBuffer []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Read(p []byte) (n int, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Write(p []byte) (n int, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Context() (ctx interface{}) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) SetContext(ctx interface{}) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Close() (err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) WriteTo(w io.Writer) (n int64, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Next(n int) (buf []byte, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
return vc.readBuffer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Peek(n int) (buf []byte, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Discard(n int) (discarded int, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) InboundBuffered() (n int) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) ReadFrom(r io.Reader) (n int64, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Writev(bs [][]byte) (n int, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Flush() (err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) OutboundBuffered() (n int) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) AsyncWrite(buf []byte, callback gnet.AsyncCallback) (err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) AsyncWritev(bs [][]byte, callback gnet.AsyncCallback) (err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Fd() int {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Dup() (int, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) SetReadBuffer(bytes int) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) SetWriteBuffer(bytes int) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) SetLinger(sec int) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) SetKeepAlivePeriod(d time.Duration) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) SetNoDelay(noDelay bool) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) LocalAddr() (addr net.Addr) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) RemoteAddr() (addr net.Addr) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) Wake(callback gnet.AsyncCallback) (err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) CloseWithCallback(callback gnet.AsyncCallback) (err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) SetDeadline(t time.Time) (err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) SetReadDeadline(t time.Time) (err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *virtualConn) SetWriteDeadline(t time.Time) (err error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|