diff --git a/server-ctl.go b/server-ctl.go index 6714fa9..6945b58 100644 --- a/server-ctl.go +++ b/server-ctl.go @@ -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)) diff --git a/server.go b/server.go index 70b6eb5..ce481bd 100644 --- a/server.go +++ b/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 }