|
|
@@ -5,6 +5,7 @@ import (
|
|
5
|
5
|
"encoding/binary"
|
|
6
|
6
|
"fmt"
|
|
7
|
7
|
"net"
|
|
|
8
|
+ "sync"
|
|
8
|
9
|
|
|
9
|
10
|
"github.com/9seconds/mtg/config"
|
|
10
|
11
|
"github.com/9seconds/mtg/conntypes"
|
|
|
@@ -19,6 +20,7 @@ type wrapperProxy struct {
|
|
19
|
20
|
clientIPPort []byte
|
|
20
|
21
|
ourIPPort []byte
|
|
21
|
22
|
channelRead hub.ChannelReadCloser
|
|
|
23
|
+ closeOnce sync.Once
|
|
22
|
24
|
}
|
|
23
|
25
|
|
|
24
|
26
|
func (w *wrapperProxy) Write(packet conntypes.Packet, acks *conntypes.ConnectionAcks) error {
|
|
|
@@ -61,7 +63,11 @@ func (w *wrapperProxy) Read(acks *conntypes.ConnectionAcks) (conntypes.Packet, e
|
|
61
|
63
|
}
|
|
62
|
64
|
|
|
63
|
65
|
func (w *wrapperProxy) Close() error {
|
|
64
|
|
- return w.channelRead.Close()
|
|
|
66
|
+ w.closeOnce.Do(func() {
|
|
|
67
|
+ w.channelRead.Close()
|
|
|
68
|
+ hub.Registry.Unregister(w.request.ConnID)
|
|
|
69
|
+ })
|
|
|
70
|
+ return nil
|
|
65
|
71
|
}
|
|
66
|
72
|
|
|
67
|
73
|
func NewProxy(request *protocol.TelegramRequest) conntypes.PacketAckReadWriteCloser {
|