@@ -52,6 +52,7 @@ func Register(router *msgpackrouter.Router) {
5252 _ = router .RegisterMethod ("udp/endPacket" , udpEndPacket )
5353 _ = router .RegisterMethod ("udp/awaitPacket" , udpAwaitPacket )
5454 _ = router .RegisterMethod ("udp/read" , udpRead )
55+ _ = router .RegisterMethod ("udp/dropPacket" , udpDropPacket )
5556 _ = router .RegisterMethod ("udp/close" , udpClose )
5657}
5758
@@ -527,6 +528,24 @@ func udpAwaitPacket(ctx context.Context, rpc *msgpackrpc.Connection, params []an
527528 return []any {n , host , port }, nil
528529}
529530
531+ func udpDropPacket (ctx context.Context , rpc * msgpackrpc.Connection , params []any ) (_result any , _err any ) {
532+ if len (params ) != 1 && len (params ) != 2 {
533+ return nil , []any {1 , "Invalid number of parameters, expected (UDP connection ID[, optional timeout in ms])" }
534+ }
535+ id , ok := msgpackrpc .ToUint (params [0 ])
536+ if ! ok {
537+ return nil , []any {1 , "Invalid parameter type, expected uint for UDP connection ID" }
538+ }
539+
540+ lock .RLock ()
541+ delete (udpReadBuffers , id )
542+ lock .RUnlock ()
543+ if ! ok {
544+ return nil , []any {2 , fmt .Sprintf ("UDP connection not found for ID: %d" , id )}
545+ }
546+ return true , nil
547+ }
548+
530549func udpRead (ctx context.Context , rpc * msgpackrpc.Connection , params []any ) (_result any , _err any ) {
531550 if len (params ) != 2 && len (params ) != 3 {
532551 return nil , []any {1 , "Invalid number of parameters, expected (UDP connection ID, max bytes to read)" }
0 commit comments