enhanced func (s *Server) FindServerConnByIdStr(conn_id string) to treat non-numeric conn_id as a connection token
This commit is contained in:
parent
d9aaa0a0ab
commit
429bb6cd63
@ -575,6 +575,7 @@ func (ctl *server_ctl_notices) ServeHTTP(w http.ResponseWriter, req *http.Reques
|
||||
goto oops
|
||||
}
|
||||
|
||||
// TODO: what if this loop takes too long? in that case, lock is held for long. think about how to handle this.
|
||||
s.cts_mtx.Lock()
|
||||
for _, cts = range s.cts_map {
|
||||
cts.pss.Send(MakeConnNoticePacket(noti.Text))
|
||||
|
12
server.go
12
server.go
@ -1841,10 +1841,14 @@ func (s *Server) FindServerConnByIdStr(conn_id string) (*ServerConn, error) {
|
||||
var err error
|
||||
|
||||
conn_nid, err = strconv.ParseUint(conn_id, 10, int(unsafe.Sizeof(ConnId(0)) * 8))
|
||||
if err != nil { return nil, fmt.Errorf("invalid connection id %s - %s", conn_id, err.Error()); }
|
||||
|
||||
cts = s.FindServerConnById(ConnId(conn_nid))
|
||||
if cts == nil { return nil, fmt.Errorf("non-existent connection id %d", conn_nid) }
|
||||
if err != nil {
|
||||
//return nil, fmt.Errorf("invalid connection id %s - %s", conn_id, err.Error()); }
|
||||
cts = s.FindServerConnByToken(conn_id) // if not numeric, attempt to use it as a token
|
||||
if cts == nil { return nil, fmt.Errorf("non-existent connection token '%s'", conn_id) }
|
||||
} else {
|
||||
cts = s.FindServerConnById(ConnId(conn_nid))
|
||||
if cts == nil { return nil, fmt.Errorf("non-existent connection id %d", conn_nid) }
|
||||
}
|
||||
|
||||
return cts, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user