Exemple #1
0
        public AsyncSocketMessageTransport([NotNull] Listener listener,
                                           [NotNull] ProcessingConfiguration processingConfiguration,
                                           [NotNull] BufferManagerFactory bufferManagerFactory)
        {
            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }
            if (processingConfiguration == null)
            {
                throw new ArgumentNullException("processingConfiguration");
            }
            if (bufferManagerFactory == null)
            {
                throw new ArgumentNullException("bufferManagerFactory");
            }

            this._listener = listener;
            // TODO добавить поддержку ограничений из processingConfiguration
            this._bodyBufferManager   = bufferManagerFactory.GetBufferManager(16, 16 * 1024, 1000);
            this._headerBufferManager = bufferManagerFactory.GetBufferManager(100, TcpMessageHeader.HeaderSize, 1000);
            ObjectPool <SocketAsyncEventArgs> socketArgsPool = new ObjectPool <SocketAsyncEventArgs>();

            //preallocate pool
            for (int i = 0; i < listener.Configuration.ConnectionCapacity; i++)
            {
                socketArgsPool.Put(new SocketAsyncEventArgs());
            }

            this._headerReciever = new Reciever <RecieveUserToken>(this._headerBufferManager, socketArgsPool);
            this._bodyReciever   = new Reciever <RecieveUserToken>(this._bodyBufferManager, socketArgsPool);
            this._sender         = new Sender <SendUserToken>(socketArgsPool);
        }
Exemple #2
0
        public NetworkStreamMessageTransport([NotNull] ProcessingConfiguration сonfiguration, [NotNull] BufferManagerFactory bufferManagerFactory)
        {
            if (сonfiguration == null)
            {
                throw new ArgumentNullException("сonfiguration");
            }
            if (bufferManagerFactory == null)
            {
                throw new ArgumentNullException("bufferManagerFactory");
            }

            this._сonfiguration       = сonfiguration;
            this._bodyBufferManager   = bufferManagerFactory.GetBufferManager(16, 16 * 1024, 1000);
            this._headerBufferManager = bufferManagerFactory.GetBufferManager(100, TcpMessageHeader.HeaderSize, 1000);
        }
Exemple #3
0
        public Listener([NotNull] ListenerConfiguration configuration,
                        [NotNull] ProcessingConfiguration processingConfiguration,
                        [NotNull] BufferManagerFactory bufferManagerFactory,
                        [NotNull] MessageTransportFactory messageTransportFactory)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            if (processingConfiguration == null)
            {
                throw new ArgumentNullException("processingConfiguration");
            }
            if (bufferManagerFactory == null)
            {
                throw new ArgumentNullException("bufferManagerFactory");
            }
            if (messageTransportFactory == null)
            {
                throw new ArgumentNullException("messageTransportFactory");
            }

            this._configuration        = configuration;
            this._bufferManagerFactory = bufferManagerFactory;

            this._clientConnectionInfoPool = new ObjectPool <ClientConnectionInfo>();
            this._disconnectSocketArgsPool = new ObjectPool <SocketAsyncEventArgs>();
            this._socketPool = new ObjectPool <Socket>();

            _connectionHolder         = new ConnectionHolder(configuration.ConnectionCapacity);
            _stoppedWaitHandle        = new ManualResetEvent(false);
            _messageTransport         = messageTransportFactory.GetMessageTransport(this);
            _compressionBufferManager = bufferManagerFactory.GetBufferManager(1024, 1024 * 8);
        }