From e418f50f2e69edccb1c50679e0cfcab41535e501 Mon Sep 17 00:00:00 2001 From: Matthias Fulz Date: Thu, 26 Mar 2020 02:12:46 +0100 Subject: [PATCH] Started simultanous client requests --- configuration.go | 5 +++-- server.go | 28 ++++++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/configuration.go b/configuration.go index c330b25..7322d36 100644 --- a/configuration.go +++ b/configuration.go @@ -21,6 +21,7 @@ const ( ) const ( - DefaultMaxClientRequests = int(128) - DefaultRequestTimeout = 30 * time.Second + DefaultMaxClientRequests = int(128) + DefaultRequestTimeout = 30 * time.Second + DefaultSimultanousClientRequests = int(5) ) diff --git a/server.go b/server.go index 5376c86..d86eded 100644 --- a/server.go +++ b/server.go @@ -61,15 +61,16 @@ func (nl *netListener) Addr() net.Addr { } type RPCServer struct { - Addr string - Listener IListener - LogError LogErrorFunc - ConnectHandler ConnectHandlerFunc - RequestDataHandler RequestDataHandlerFunc - RequestHandler RequestHandlerFunc - Ed IEncoderDecoder - stopChan chan struct{} - stopWg sync.WaitGroup + Addr string + Listener IListener + LogError LogErrorFunc + ConnectHandler ConnectHandlerFunc + RequestDataHandler RequestDataHandlerFunc + RequestHandler RequestHandlerFunc + SimultanousClientRequests int + Ed IEncoderDecoder + stopChan chan struct{} + stopWg sync.WaitGroup } func (s *RPCServer) Start() (err error) { @@ -90,6 +91,10 @@ func (s *RPCServer) Start() (err error) { return errors.New("srpc - Server needs a RequestHandler") } + if s.SimultanousClientRequests == 0 { + s.SimultanousClientRequests = DefaultSimultanousClientRequests + } + if s.Listener == nil { s.Listener = &netListener{} } @@ -163,7 +168,10 @@ func serverHandler(s *RPCServer) { } func serverHandleConnection(s *RPCServer, conn io.ReadWriteCloser, clientAddr string) { - defer s.stopWg.Done() + defer func() { + fmt.Println("Client disconnected") + s.stopWg.Done() + }() if s.ConnectHandler != nil { if newConn, err := s.ConnectHandler(clientAddr, conn); err != nil {