Пример #1
0
        public void Complete(int bytes_transferred, bool success, int error, object context)
        {
            if (!_acceptor.IsListening)
            {
                _acceptor.Logger.Info("获取连接返回,但已经停止监听!");
                _acceptor.DecrementAccepting();
                return;
            }

            if (!success)
            {
                Exception err = new SocketException(error);
                _acceptor.OnError(new AcceptError(_acceptor.BindPoint, string.Format("获取端口[{0}]的连接失败 - {1}!", _acceptor.BindPoint, err.Message), err));
            }
            else
            {
                InitializeConnection(bytes_transferred, context);
            }

            try
            {
                _acceptor.doAccept();
            }
            catch (AcceptError e)
            {
                _acceptor.OnError(e);
            }
            catch (Exception e)
            {
                _acceptor.OnError(new AcceptError(_acceptor.BindPoint, e));
            }

            _acceptor.DecrementAccepting();
        }