Пример #1
0
        /// <inheritdoc />
        /// <exception cref="ArgumentNullException" />
        /// <exception cref="ArgumentOutOfRangeException" />
        public SocketListener(EndPoint listenEndPoint, int backlog, int maxConnections, IPacketProcessor packetProcessor)
        {
            if (listenEndPoint == null)
            {
                throw new ArgumentNullException(nameof(listenEndPoint));
            }
            if (backlog <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(backlog));
            }
            if (maxConnections <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxConnections));
            }
            if (packetProcessor == null)
            {
                throw new ArgumentNullException(nameof(packetProcessor));
            }

            this.listenEndPoint         = listenEndPoint;
            this.backlog                = backlog;
            this.maxConnections         = maxConnections;
            this.packetProcessor        = packetProcessor;
            this.sendOperation          = SocketOperation.Asynchronization;
            this.bufferSize             = SocketConstants.DefaultBufferSize;
            this.keepAlive              = KeepAlive.OFF;
            this.maxConnectionsEnforcer = new Semaphore(maxConnections, maxConnections);
            this.statistics             = new SocketListenerStatistics();

            this.acceptEventArgs            = new SocketAsyncEventArgs();
            this.acceptEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(Accept_Completed);
            this.ioEventArgsPool            = new ConcurrentStack <SocketAsyncEventArgs>();
        }
Пример #2
0
        /// <inheritdoc />
        public TcpClient(IPacketProcessor packetProcessor)
        {
            if (packetProcessor == null)
            {
                throw new ArgumentNullException(nameof(packetProcessor));
            }

            this.packetProcessor = packetProcessor;
            this.bufferSize      = SocketConstants.DefaultBufferSize;
            this.keepAlive       = KeepAlive.OFF;
        }