Started simultanous client requests
This commit is contained in:
parent
231f347976
commit
e418f50f2e
|
@ -23,4 +23,5 @@ const (
|
|||
const (
|
||||
DefaultMaxClientRequests = int(128)
|
||||
DefaultRequestTimeout = 30 * time.Second
|
||||
DefaultSimultanousClientRequests = int(5)
|
||||
)
|
||||
|
|
10
server.go
10
server.go
|
@ -67,6 +67,7 @@ type RPCServer struct {
|
|||
ConnectHandler ConnectHandlerFunc
|
||||
RequestDataHandler RequestDataHandlerFunc
|
||||
RequestHandler RequestHandlerFunc
|
||||
SimultanousClientRequests int
|
||||
Ed IEncoderDecoder
|
||||
stopChan chan struct{}
|
||||
stopWg sync.WaitGroup
|
||||
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue