File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ const (
83
83
var (
84
84
errInvalidOperation = errors .New ("invalid operation" )
85
85
errTimeout = errors .New ("timeout" )
86
+ errNotOwner = errors .New ("not the owner of this connection" )
86
87
)
87
88
88
89
var (
@@ -590,6 +591,18 @@ func (s *UDPSession) SetWriteBuffer(bytes int) error {
590
591
return errInvalidOperation
591
592
}
592
593
594
+ // Control applys a procedure to the underly socket fd.
595
+ // CAUTION: BE VERY CAREFUL TO USE THIS FUNCTION, YOU MAY BREAK THE PROTOCOL.
596
+ func (s * UDPSession ) Control (f func (conn net.PacketConn ) error ) error {
597
+ if ! s .ownConn {
598
+ return errNotOwner
599
+ }
600
+
601
+ s .mu .Lock ()
602
+ defer s .mu .Unlock ()
603
+ return f (s .conn )
604
+ }
605
+
593
606
// a goroutine to handle post processing of kcp and make the critical section smaller
594
607
// pipeline for outgoing packets (from ARQ to network)
595
608
//
@@ -1060,6 +1073,14 @@ func (l *Listener) Close() error {
1060
1073
return err
1061
1074
}
1062
1075
1076
+ // Control applys a procedure to the underly socket fd.
1077
+ // CAUTION: BE VERY CAREFUL TO USE THIS FUNCTION, YOU MAY BREAK THE PROTOCOL.
1078
+ func (l * Listener ) Control (f func (conn net.PacketConn ) error ) error {
1079
+ l .sessionLock .Lock ()
1080
+ defer l .sessionLock .Unlock ()
1081
+ return f (l .conn )
1082
+ }
1083
+
1063
1084
// closeSession notify the listener that a session has closed
1064
1085
func (l * Listener ) closeSession (remote net.Addr ) (ret bool ) {
1065
1086
l .sessionLock .Lock ()
You can’t perform that action at this time.
0 commit comments