Example #1
0
        /// <summary>
        /// Accept callback, start receive message body
        /// </summary>
        /// <param name="ar"></param>
        private void AcceptCallback(IAsyncResult ar)
        {
            Socket sock = null;

            try
            {
                sock = _listeningSocket.EndAccept(ar);

                var connection = _connectionsPool.Get();
                if (connection == null)
                {
                    Log.Info("Connections limit reached! Can't accept new connection");
                }
                else
                {
                    connection.Socket = sock;
                    connection.Socket.BeginSend(_key, 0, _key.Length, SocketFlags.None, null, null);
                    connection.Socket.BeginReceive(connection.WaitPacketLen, 0,
                                                   connection.WaitPacketLen.Length, SocketFlags.None, ReceivePacketCallback, connection);
                }
            }
            catch (Exception)
            {
                sock?.Close();
            }
            _listeningSocket.BeginAccept(AcceptCallback, null);
        }
Example #2
0
        private void AcceptCallback(IAsyncResult ar)
        {
            Socket sock = null;

            try
            {
                sock = _listeningSocket.EndAccept(ar);

                var connection = _connectionsPool.Get();
                if (connection == null)
                {
                    _log.Warn("Connections limit reached! Can't accept new connection");
                }
                else
                {
                    _log.Info($"Client {sock.RemoteEndPoint} connected!");

                    connection.Socket = sock;
                    connection.Socket.BeginReceive(connection.WaitPacketLength, 0, 2, SocketFlags.None, ReadCallback, connection);
                }
            }
            catch (Exception ex)
            {
                sock?.Close();

                _log.Error(ex);
            }

            _listeningSocket.BeginAccept(AcceptCallback, null);
        }
Example #3
0
 public void OnProjectileRegistryHits(Projectile proj, CastHitsInfo hitsInfo)
 {
     if (proj == null || hitsInfo.Count == 0)
     {
         return;
     }
     //Мгновенная обработка попадания
     if (proj.Data.Instantly)
     {
         var hitInfo = pool.Get();
         hitInfo.Init(proj, hitsInfo).Set();
         pool.Return(hitInfo);
     }
     else
     {
         hits.Add(pool.Get().Init(proj, hitsInfo));
     }
 }
Example #4
0
    public int Add(T elem)
    {
        int id = 0;

        if (elem != null)
        {
            id = ++ids;
            elems.Add(nodePool.Get().Set(id, elem));
        }
        return(id);
    }
 public static NetworkHits Get()
 {
     return(m_PoolHits.Get());
 }