From f14efa64f09f81681f94a1e25c8297eafca54d88 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 15 Dec 2020 11:52:05 +0300 Subject: [PATCH] server: add MaxConn and Listener options Signed-off-by: Vasiliy Tolstov --- server/options.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/options.go b/server/options.go index d154842b..704aa112 100644 --- a/server/options.go +++ b/server/options.go @@ -3,6 +3,7 @@ package server import ( "context" "crypto/tls" + "net" "sync" "time" @@ -57,6 +58,8 @@ type Options struct { Wait *sync.WaitGroup + // Listener may be passed if already created + Listener net.Listener // MaxConn limit connections to server MaxConn int // Other options for implementations of the interface @@ -272,6 +275,20 @@ func WrapSubscriber(w SubscriberWrapper) Option { } } +// MaxConn specifies maximum number of max simultaneous connections to server +func MaxConn(n int) Option { + return func(o *Options) { + o.MaxConn = n + } +} + +// Listener specifies the net.Listener to use instead of the default +func Listener(l net.Listener) Option { + return func(o *Options) { + o.Listener = l + } +} + // HandlerOption func type HandlerOption func(*HandlerOptions)