added ReqStopAllServerConns() to the Server type

This commit is contained in:
hyung-hwan 2024-12-02 09:46:10 +09:00
parent c901f88023
commit eef1941dea
2 changed files with 22 additions and 1 deletions

View File

@ -23,6 +23,10 @@ type server_ctl_server_conns struct {
s *Server s *Server
} }
type server_ctl_server_conns_id struct {
s *Server
}
// ------------------------------------ // ------------------------------------
func (ctl *server_ctl_server_conns) ServeHTTP(w http.ResponseWriter, req *http.Request) { 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 } if err = je.Encode(js); err != nil { goto oops }
case http.MethodDelete: case http.MethodDelete:
// TODO s.ReqStopAllServerConns() s.ReqStopAllServerConns()
status_code = http.StatusNoContent; w.WriteHeader(status_code) status_code = http.StatusNoContent; w.WriteHeader(status_code)
default: default:
@ -78,3 +82,9 @@ oops:
s.log.Write("", LOG_ERROR, "[%s] %s %s - %s", req.RemoteAddr, req.Method, req.URL.String(), err.Error()) s.log.Write("", LOG_ERROR, "[%s] %s %s - %s", req.RemoteAddr, req.Method, req.URL.String(), err.Error())
return return
} }
// ------------------------------------
func (ctl *server_ctl_server_conns_id) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// TODO:
}

View File

@ -895,6 +895,17 @@ func (s *Server) AddNewServerConn(remote_addr *net.Addr, local_addr *net.Addr, p
return &cts, nil 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) { func (s *Server) RemoveServerConn(cts *ServerConn) {
s.cts_mtx.Lock() s.cts_mtx.Lock()
delete(s.cts_map, cts.caddr) delete(s.cts_map, cts.caddr)