/// <summary> /// 将一个端点(对应一个客户端)添加至连接列表。如果列表中已有此端点,则返回对应的连接列表项。 /// <para>注意,本方法执行中会为 ConnectionList 加锁。</para> /// </summary> /// <param name="endPoint">要添加的客户端的端点。</param> /// <returns>一个 <see cref="Kei.KNetwork.ConnectionListItem"/>,表示添加或者找到的连接列表项。</returns> private ConnectionListItem AddToConnectionList(KEndPoint endPoint) { if (endPoint.Equals(LocalKEndPoint)) { Logger.Log("KClient::AddToConnectionList(KEndPoint): 不能加入自己"); return(null); } Logger.Log("KClient::AddToConnectionList(KEndPoint)" + Environment.NewLine + "待加入的端点: " + endPoint.ToString()); int index; var connItem = ConnectionList.FindConnectionListItem(endPoint, out index); if (connItem == null) { Logger.Log("在列表中未发现,即将加入。"); connItem = new ConnectionListItem(endPoint); lock (ConnectionList) { ConnectionList.Add(connItem); EventHelper.RaiseEvent(ConnectionListChanged, this, EventArgs.Empty); } } return(connItem); }