Started simultanous client requests
This commit is contained in:
parent
231f347976
commit
e418f50f2e
|
@ -21,6 +21,7 @@ const (
|
|||
)
|
||||
|
||||
const (
|
||||
DefaultMaxClientRequests = int(128)
|
||||
DefaultRequestTimeout = 30 * time.Second
|
||||
DefaultMaxClientRequests = int(128)
|
||||
DefaultRequestTimeout = 30 * time.Second
|
||||
DefaultSimultanousClientRequests = int(5)
|
||||
)
|
||||
|
|
28
server.go
28
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 {
|
||||
|
|
Loading…
Reference in New Issue