diff options
Diffstat (limited to 'src/hub/src/spreadspace.org/sfive/s5srvPipe.go')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5srvPipe.go | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvPipe.go b/src/hub/src/spreadspace.org/sfive/s5srvPipe.go index c291513..46a83cc 100644 --- a/src/hub/src/spreadspace.org/sfive/s5srvPipe.go +++ b/src/hub/src/spreadspace.org/sfive/s5srvPipe.go @@ -37,6 +37,7 @@ import ( "io" "net" "strings" + "sync" ) func (srv *Server) pipeHandle(conn net.Conn) { @@ -79,28 +80,34 @@ func (srv *Server) pipeHandle(conn net.Conn) { } func (srv *Server) pipeRun() { + var wgClients sync.WaitGroup for { conn, err := srv.interfaces.pipe.Accept() if err != nil { if strings.Contains(err.Error(), "use of closed network connection") { // TODO: is this really the best way to do this? - return + break } s5l.Printf("srv|pipe: accept() failed: %v", err) // ignore continue } - go srv.pipeHandle(conn) + wgClients.Add(1) + go func() { + defer wgClients.Done() + srv.pipeHandle(conn) + }() } + s5l.Println("srv|pipe: interface stopped listening") + // TODO: tell all clients to disconnect!!! + wgClients.Wait() } func (srv *Server) pipeStop(ctx context.Context) (err error) { - // TODO: this is a race condition between a call to pipeRun and pipeStop... if srv.interfaces.pipe == nil { return nil } s5l.Printf("srv|pipe: shutting down") return srv.interfaces.pipe.Close() - // TODO: also close alle open client file descriptors } func (srv *Server) ServePipe(cfg PipeInterfaceConfig) (err error) { @@ -110,8 +117,12 @@ func (srv *Server) ServePipe(cfg PipeInterfaceConfig) (err error) { } s5l.Printf("srv|pipe: listening on '%s'", cfg.ListenPath) - defer s5l.Println("srv|pipe: interface stopped") - srv.pipeRun() + srv.wgInterfaces.Add(1) + go func() { + defer srv.wgInterfaces.Done() + + srv.pipeRun() + }() return } |