From eef1941dea28a97a901a235fca35bd00f64266cf Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 2 Dec 2024 09:46:10 +0900 Subject: [PATCH] added ReqStopAllServerConns() to the Server type --- server-ctl.go | 12 +++++++++++- server.go | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/server-ctl.go b/server-ctl.go index 0264c70..30a1649 100644 --- a/server-ctl.go +++ b/server-ctl.go @@ -23,6 +23,10 @@ type server_ctl_server_conns struct { s *Server } +type server_ctl_server_conns_id struct { + s *Server +} + // ------------------------------------ func (ctl *server_ctl_server_conns) ServeHTTP(w http.ResponseWriter, req *http.Request) { @@ -63,7 +67,7 @@ func (ctl *server_ctl_server_conns) ServeHTTP(w http.ResponseWriter, req *http.R if err = je.Encode(js); err != nil { goto oops } case http.MethodDelete: -// TODO s.ReqStopAllServerConns() + s.ReqStopAllServerConns() status_code = http.StatusNoContent; w.WriteHeader(status_code) default: @@ -78,3 +82,9 @@ oops: s.log.Write("", LOG_ERROR, "[%s] %s %s - %s", req.RemoteAddr, req.Method, req.URL.String(), err.Error()) return } + +// ------------------------------------ + +func (ctl *server_ctl_server_conns_id) ServeHTTP(w http.ResponseWriter, req *http.Request) { + // TODO: +} diff --git a/server.go b/server.go index 802e18b..77b36a0 100644 --- a/server.go +++ b/server.go @@ -895,6 +895,17 @@ func (s *Server) AddNewServerConn(remote_addr *net.Addr, local_addr *net.Addr, p return &cts, nil } +func (s *Server) ReqStopAllServerConns() { + var cts *ServerConn + + s.cts_mtx.Lock() + defer s.cts_mtx.Unlock() + + for _, cts = range s.cts_map { + cts.ReqStop() + } +} + func (s *Server) RemoveServerConn(cts *ServerConn) { s.cts_mtx.Lock() delete(s.cts_map, cts.caddr)