コード例 #1
0
        private void ProcessAccept(SocketAsyncEventArgs acceptEventArgs)
        {
            if (_communicationProvisioning != null)
            {
                if (!_communicationProvisioning.AllowedEndpoints.Any(ep => ep.Address.Equals(((IPEndPoint)acceptEventArgs.RemoteEndPoint).Address)))
                {
                    HandleBadAccept(acceptEventArgs);
                    return;
                }
            }

            if (acceptEventArgs.SocketError != SocketError.Success)
            {
                StartAccept();

                HandleBadAccept(acceptEventArgs);
            }
            else
            {
                StartAccept();

                try
                {
                    InitializeCommunicationChannel(acceptEventArgs.AcceptSocket);
                }
                finally
                {
                    acceptEventArgs.AcceptSocket = null;
                    _acceptEventArgsPool.Push(acceptEventArgs);
                }
            }
        }
コード例 #2
0
        protected virtual void ReleaseClientHandler(ICommunicationChannel communicationChannel)
        {
            if (_clientConnectedList.Contains(communicationChannel))
            {
                _clientConnectedList.Remove(communicationChannel);
            }

            _communicationChannelsPool.Push(communicationChannel);

            Interlocked.Decrement(ref _connectedSockets);
            _log.Info($"Socket with IP {communicationChannel.RemoteIPAddress} disconnected. {_connectedSockets} client(s) connected.");
        }
コード例 #3
0
        public TcpCommunicationService(IApplicationContext applicationContext, ILoggerService loggerService, IBufferManagerFactory bufferManagerFactory, IPacketsHandler packetsHandler, INodesResolutionService nodesResolutionService)
            : base(applicationContext, loggerService, bufferManagerFactory, packetsHandler, nodesResolutionService)
        {
            _acceptEventArgsPool = new GenericPool <SocketAsyncEventArgs>(10);

            for (Int32 i = 0; i < 10; i++)
            {
                _acceptEventArgsPool.Push(CreateNewSocketAsyncEventArgs(_acceptEventArgsPool));
            }
        }
コード例 #4
0
        /// <summary>
        /// Initializes the server by preallocating reusable buffers and
        /// context objects.  These objects do not need to be preallocated
        /// or reused, but it is done this way to illustrate how the API can
        /// easily be used to create reusable objects to increase server performance.
        /// </summary>
        public virtual void Init(SocketSettings settings)
        {
            _settings = settings;

            // Allocates one large byte buffer which all I/O operations use a piece of.  This guards against memory fragmentation
            IBufferManager bufferManager = _bufferManagerFactory.Create();

            bufferManager.InitBuffer(_settings.BufferSize * _settings.MaxConnections * 2, _settings.BufferSize);
            _communicationChannelsPool = new GenericPool <ICommunicationChannel>(_settings.MaxConnections);

            for (int i = 0; i < _settings.MaxConnections; i++)
            {
                ICommunicationChannel communicationChannel = _applicationContext.Container.Resolve <ICommunicationChannel>();
                communicationChannel.SocketClosedEvent += ClientHandler_SocketClosedEvent;
                communicationChannel.Init(bufferManager, _packetsHandler);
                _communicationChannelsPool.Push(communicationChannel);
            }
        }
コード例 #5
0
 public void Push(AnimationManager.BlowPieceAnimation blowAnimation)
 {
     _blowAnimPool.Push(blowAnimation);
 }
コード例 #6
0
 public void Push(AnimationManager.MovePieceAnimation moveAnimation)
 {
     _moveAnimPool.Push(moveAnimation);
 }
コード例 #7
0
 public void Push(HexagonMatch match)
 {
     _matchPool.Push(match);
 }
コード例 #8
0
 public void Push(HexagonBomb bomb)
 {
     bomb.transform.parent.GetComponent <SpriteRenderer>().sprite = piecePrefab.GetComponent <SpriteRenderer>().sprite;
     _bombPool.Push(bomb);
 }
コード例 #9
0
 public void Push(HexagonPiece piece)
 {
     _piecePool.Push(piece);
 }