Ejemplo n.º 1
0
        protected override void DoBind(EndPoint localAddress)
        {
            if (!this.Open)
            {
                return;
            }

            Debug.Assert(this.EventLoop.InEventLoop);
            if (!this.IsInState(StateFlags.Active))
            {
                var address      = (IPEndPoint)localAddress;
                var loopExecutor = (LoopExecutor)this.EventLoop;

                uint flags = PlatformApi.GetAddressFamily(address.AddressFamily);
                this.tcpListener = new TcpListener(loopExecutor.UnsafeLoop, flags);

                // Apply the configuration right after the tcp handle is created
                // because SO_REUSEPORT cannot be configured after bind
                this.config.Apply();

                this.tcpListener.Bind(address);
                this.isBound = true;

                this.tcpListener.Listen((TcpServerChannelUnsafe)this.Unsafe, this.config.Backlog);

                this.CacheLocalAddress();
                this.SetState(StateFlags.Active);
            }
        }