discard client input after onNewClient callback finished
This commit is contained in:
parent
5aa9db4e51
commit
c86730cabc
17
server.go
17
server.go
@ -30,14 +30,6 @@ func Listen(socketPath string, onNewClient func(client net.Conn)) (*Server, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if onNewClient == nil {
|
|
||||||
onNewClient = func(client net.Conn) {
|
|
||||||
data := make([]byte, 1024)
|
|
||||||
for _, err := client.Read(data); err == nil; _, err = client.Read(data) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
s := &Server{
|
s := &Server{
|
||||||
socketPath: absPath,
|
socketPath: absPath,
|
||||||
server: server,
|
server: server,
|
||||||
@ -70,7 +62,14 @@ func (s *Server) handleClients() {
|
|||||||
func (s *Server) handleClient(client net.Conn) {
|
func (s *Server) handleClient(client net.Conn) {
|
||||||
s.clients.Put(client, struct{}{})
|
s.clients.Put(client, struct{}{})
|
||||||
defer s.clients.Delete(client)
|
defer s.clients.Delete(client)
|
||||||
s.onNewClient(client)
|
|
||||||
|
if s.onNewClient != nil {
|
||||||
|
s.onNewClient(client)
|
||||||
|
}
|
||||||
|
|
||||||
|
data := make([]byte, 1024)
|
||||||
|
for _, err := client.Read(data); err == nil; _, err = client.Read(data) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Close() error {
|
func (s *Server) Close() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user