Example #1
0
 public ServerAcceptor(SocketType socketType, ProtocolType protocolType, ISocketAsyncEventArgsPool acceptorPool, Func<SocketAsyncEventArgs> acceptorFactory)
 {
     this.socketType = socketType;
     this.protocolType = protocolType;
     this.acceptorPool = acceptorPool;
     this.acceptorFactory = acceptorFactory;
 }
 public ServerAcceptor(SocketType socketType, ProtocolType protocolType, ISocketAsyncEventArgsPool acceptorPool, Func <SocketAsyncEventArgs> acceptorFactory)
 {
     this.socketType      = socketType;
     this.protocolType    = protocolType;
     this.acceptorPool    = acceptorPool;
     this.acceptorFactory = acceptorFactory;
 }
Example #3
0
 public void Initialize(IEndPointStation endpointStation, ISocketAsyncEventArgsPool recvArgsPool, IPool <ArraySegment <byte> > dataBufferPool, IPool <ISocketSender> socketSenderPool)
 {
     _EndPointStation     = endpointStation;
     ReceiveEventArgsPool = recvArgsPool;
     DataBufferPool       = dataBufferPool;
     SocketSenderPool     = socketSenderPool;
     EndpointStateFactory = _ => new EndpointState(DataBufferPool, SocketSenderPool);
     MessageHandlerFunc   = HandleReceivedMessageAsync;
 }
Example #4
0
        public ServerSocketSlim(IBufferManager bufferManager, int maxSimultaneousConnections, int preallocatedDataCount, int acceptorPoolSize = 100, int maxPendingConnections = 100)
        {
            this.bufferManager = bufferManager;
            // set up acceptor
            ISocketAsyncEventArgsPool acceptorPool = CreateAcceptorPool(acceptorPoolSize);

            serverAcceptor = new ServerAcceptor(SocketType.Stream, ProtocolType.Tcp, acceptorPool, CreateAcceptor)
            {
                MaxSimultaneousConnections = maxSimultaneousConnections,
                MaxPendingConnections      = maxPendingConnections
            };

            serverAcceptor.Accepted     += OnServerAcceptorAccepted;
            serverAcceptor.AcceptFailed += OnServerAcceptorAcceptFailed;

            // remove data pool when no preallocation is happening
            if (preallocatedDataCount <= 0)
            {
                channelDataPool = null;
                return;
            }

            // preallocate data for channels
            List <PreallocatedChannelData> preallocatedChannelData = new List <PreallocatedChannelData>();

            for (int i = 0; i < preallocatedDataCount; i++)
            {
                preallocatedChannelData.Add(new PreallocatedChannelData());
            }

            // set up receivers and senders
            foreach (PreallocatedChannelData channelData in preallocatedChannelData)
            {
                channelData.InitReceiver(bufferManager);
            }
            foreach (PreallocatedChannelData channelData in preallocatedChannelData)
            {
                channelData.InitSender(bufferManager);
            }

            // and add them into the pool
            foreach (PreallocatedChannelData channelData in preallocatedChannelData)
            {
                channelDataPool.PutObject(channelData);
            }
        }
 private SocketAsyncEventArgsPoolManager()
 {
     _receiveSaeaPool = new BufferedSocketAsyncEventArgsPool(
         ReceiveSaeaPoolSize, ReceiveBufferSize, IOCompleted);
     _sendSaeaPool = new SocketAsyncEventArgsPool(SendSaeaPoolSize, IOCompleted);
 }