addimg more client side manpulation code
This commit is contained in:
parent
f6de948a5a
commit
bee458a47d
@ -216,7 +216,6 @@ func (ctl *client_ctl_client_conns_id) ServeHTTP(w http.ResponseWriter, req *htt
|
|||||||
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
|
|
||||||
err = c.RemoveClientConnById(uint32(conn_nid))
|
err = c.RemoveClientConnById(uint32(conn_nid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
status_code = http.StatusNotFound; w.WriteHeader(status_code)
|
status_code = http.StatusNotFound; w.WriteHeader(status_code)
|
||||||
@ -224,7 +223,7 @@ func (ctl *client_ctl_client_conns_id) ServeHTTP(w http.ResponseWriter, req *htt
|
|||||||
} else {
|
} else {
|
||||||
status_code = http.StatusNoContent; w.WriteHeader(status_code)
|
status_code = http.StatusNoContent; w.WriteHeader(status_code)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
default:
|
default:
|
||||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||||
}
|
}
|
||||||
|
46
client.go
46
client.go
@ -704,7 +704,7 @@ fmt.Printf("context doine... error - %s\n", cts.cli.ctx.Err().Error())
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
cts.cli.log.Write("", LOG_INFO, "Disconnected from server %s", cts.cfg.ServerAddr)
|
cts.cli.log.Write("", LOG_INFO, "Disconnected from server %s", cts.cfg.ServerAddr)
|
||||||
//cts.RemoveClientRoutes()
|
//cts.RemoveClientRoutes() // this isn't needed as each task removes itself from cts upon its termination
|
||||||
cts.ReqStop()
|
cts.ReqStop()
|
||||||
wait_for_termination:
|
wait_for_termination:
|
||||||
cts.route_wg.Wait() // wait until all route tasks are finished
|
cts.route_wg.Wait() // wait until all route tasks are finished
|
||||||
@ -821,12 +821,54 @@ fmt.Printf("ADD total servers %d\n", len(c.cts_map))
|
|||||||
return cts, nil
|
return cts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) RemoveClientConn(cts *ClientConn) {
|
func (c *Client) RemoveClientConn(cts *ClientConn) error {
|
||||||
|
var conn *ClientConn
|
||||||
|
var ok bool
|
||||||
|
|
||||||
c.cts_mtx.Lock()
|
c.cts_mtx.Lock()
|
||||||
|
|
||||||
|
conn, ok = c.cts_map[cts.cfg.ServerAddr]
|
||||||
|
if !ok {
|
||||||
|
c.cts_mtx.Unlock()
|
||||||
|
return fmt.Errorf("non-existent connection id - %d", cts.id)
|
||||||
|
}
|
||||||
|
if conn != cts {
|
||||||
|
c.cts_mtx.Unlock()
|
||||||
|
return fmt.Errorf("non-existent connection id - %d", cts.id)
|
||||||
|
}
|
||||||
|
|
||||||
delete(c.cts_map, cts.cfg.ServerAddr)
|
delete(c.cts_map, cts.cfg.ServerAddr)
|
||||||
delete(c.cts_map_by_id, cts.id)
|
delete(c.cts_map_by_id, cts.id)
|
||||||
fmt.Printf("REMOVEDDDDDD CONNECTION FROM %s total servers %d\n", cts.cfg.ServerAddr, len(c.cts_map))
|
fmt.Printf("REMOVEDDDDDD CONNECTION FROM %s total servers %d\n", cts.cfg.ServerAddr, len(c.cts_map))
|
||||||
c.cts_mtx.Unlock()
|
c.cts_mtx.Unlock()
|
||||||
|
|
||||||
|
c.ReqStop()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) RemoveClientConnById(conn_id uint32) error {
|
||||||
|
var cts *ClientConn
|
||||||
|
var ok bool
|
||||||
|
|
||||||
|
c.cts_mtx.Lock()
|
||||||
|
|
||||||
|
cts, ok = c.cts_map_by_id[conn_id]
|
||||||
|
if !ok {
|
||||||
|
c.cts_mtx.Unlock()
|
||||||
|
return fmt.Errorf("non-existent connection id - %d", conn_id)
|
||||||
|
}
|
||||||
|
if cts != cts {
|
||||||
|
c.cts_mtx.Unlock()
|
||||||
|
return fmt.Errorf("non-existent connection id - %d", conn_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(c.cts_map, cts.cfg.ServerAddr)
|
||||||
|
delete(c.cts_map_by_id, cts.id)
|
||||||
|
fmt.Printf("REMOVEDDDDDD CONNECTION FROM %s total servers %d\n", cts.cfg.ServerAddr, len(c.cts_map))
|
||||||
|
c.cts_mtx.Unlock()
|
||||||
|
|
||||||
|
cts.ReqStop()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) FindClientConnById(id uint32) *ClientConn {
|
func (c *Client) FindClientConnById(id uint32) *ClientConn {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user