Пример #1
0
 public void CloseOneConnection(FastSocketConnection fastSocketConnection)
 {
     if (fastSocketConnection != null)
     {
         fastSocketConnection.Close();
     }
 }
Пример #2
0
 private void HandleListenAsync()
 {
     if (this.IsListen)
     {
         this.socket.BeginAccept(asyncResult =>
         {
             try
             {
                 Socket newConnectionSocket = this.socket?.EndAccept(asyncResult);
                 if (this.IsListen)
                 {
                     this.HandleListenAsync();
                 }
                 else
                 {
                     newConnectionSocket.Close();
                     return;
                 }
                 if (this.Connections.Count(p => p.Enable) >= this.MaxConnections)
                 {
                     newConnectionSocket.Close();
                     return;
                 }
                 else
                 {
                     FastSocketConnection fastSocketConnection = new FastSocketConnection(newConnectionSocket, (int)asyncResult.AsyncState, this);
                     fastSocketConnection.Start();
                 }
             }
             catch (Exception ex)
             {
                 this.FastSocketService.OnServiceException(this, ex);
             }
         }, this.AutoGrowthConnectionId++);
     }
 }