mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-31 22:45:39 -05:00
Stats: Implements blocking/non-blocking messaging of Channel (#250)
This commit is contained in:
@@ -6,6 +6,7 @@ package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
@@ -38,7 +39,8 @@ func (s *routingServer) TestRoute(ctx context.Context, request *TestRouteRequest
|
||||
return nil, err
|
||||
}
|
||||
if request.PublishResult && s.routingStats != nil {
|
||||
s.routingStats.Publish(route)
|
||||
ctx, _ := context.WithTimeout(context.Background(), 4*time.Second) // nolint: lostcancel
|
||||
s.routingStats.Publish(ctx, route)
|
||||
}
|
||||
return AsProtobufMessage(request.FieldSelectors)(route), nil
|
||||
}
|
||||
@@ -55,10 +57,13 @@ func (s *routingServer) SubscribeRoutingStats(request *SubscribeRoutingStatsRequ
|
||||
defer stats.UnsubscribeClosableChannel(s.routingStats, subscriber) // nolint: errcheck
|
||||
for {
|
||||
select {
|
||||
case value, received := <-subscriber:
|
||||
case value, ok := <-subscriber:
|
||||
if !ok {
|
||||
return newError("Upstream closed the subscriber channel.")
|
||||
}
|
||||
route, ok := value.(routing.Route)
|
||||
if !(received && ok) {
|
||||
return newError("Receiving upstream statistics failed.")
|
||||
if !ok {
|
||||
return newError("Upstream sent malformed statistics.")
|
||||
}
|
||||
err := stream.Send(genMessage(route))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user