From fb0f05b1594bbfc859e44f0265195334249d6990 Mon Sep 17 00:00:00 2001 From: FH0 <32861476+FH0@users.noreply.github.com> Date: Wed, 18 Mar 2020 19:26:48 +0800 Subject: [PATCH] fix udp broken --- common/buf/copy.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/buf/copy.go b/common/buf/copy.go index 87a9518e..c1721eb5 100644 --- a/common/buf/copy.go +++ b/common/buf/copy.go @@ -8,6 +8,11 @@ import ( "v2ray.com/core/common/signal" ) +// ActivityNotifiable is a object that accepts activity notification outside the object +type ActivityNotifiable interface { + NotifyActivity() error +} + type dataHandler func(MultiBuffer) type copyHandler struct { @@ -31,6 +36,15 @@ func UpdateActivity(timer signal.ActivityUpdater) CopyOption { } } +// NotifyActivity is a CopyOption to notify activity on each data copy operation. +func NotifyActivity(notifier ActivityNotifiable) CopyOption { + return func(handler *copyHandler) { + handler.onData = append(handler.onData, func(MultiBuffer) { + notifier.NotifyActivity() + }) + } +} + // CountSize is a CopyOption that sums the total size of data copied into the given SizeCounter. func CountSize(sc *SizeCounter) CopyOption { return func(handler *copyHandler) {