Exemplo n.º 1
0
        public void ProcessPoll(PollMode mode, State thisState)
        {
            var thisValue = GetValue(thisState);

            if (thisValue == _lastValue)
            {
                return;
            }
            var report = BuildReport(thisState);

            switch (mode)
            {
            case PollMode.Bind:
                OnBindMode(this, new InputReportEventArgs(report));
                break;

            case PollMode.Subscription:
                foreach (var observer in _observers)
                {
                    ThreadPool.QueueUserWorkItem(threadProc => observer.OnNext(report));
                }
                break;

            default:
                throw new Exception($"Unknown Poll Mode: {mode}");
            }

            _lastValue = thisValue;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 注册Socket
        /// </summary>
        /// <param name="socket">待注册的Socket</param>
        /// <param name="mode">注册的状态</param>
        public void Register(Socket socket, PollMode mode)
        {
            //如果注册的状态为可写
            RegisterReadSocket(socket, mode);

            //如果注册的状态为可读
            RegisterWriteSocket(socket, mode);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 注册可读的Socket
        /// </summary>
        /// <param name="socket">待注册可读的Socket</param>
        /// <param name="mode">注册状态</param>
        private void RegisterReadSocket(Socket socket, PollMode mode)
        {
            //如果注册状态为可读
            if ((mode & PollMode.PollIn) != 0)
            {
                if (!readList.Contains(socket))
                {
                    readList.Add(socket);
                }
            }

            //否则取消Socket
            else
            {
                readList.Remove(socket);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 注册可写的Socket
        /// </summary>
        /// <param name="socket">待注册可写的Socket</param>
        /// <param name="mode">注册状态</param>
        private void RegisterWriteSocket(Socket socket, PollMode mode)
        {
            //如果注册状态为可写
            if ((mode & PollMode.PollOut) != 0)
            {
                if (!writeList.Contains(socket))
                {
                    writeList.Add(socket);
                }
            }

            //否则取消Socket
            else
            {
                writeList.Remove(socket);
            }
        }
Exemplo n.º 5
0
 public PollModeAttribute(PollMode pollMode)
 {
     PollMode = pollMode;
 }
Exemplo n.º 6
0
 public void SetBindModeState(bool state)
 {
     PollMode = state ? PollMode.Bind : PollMode.Subscription;
 }
Exemplo n.º 7
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="socket">套接字</param>
 /// <param name="mode">Poll的状态</param>
 public PollItem(Socket socket, PollMode mode)
 {
     this.socket = socket;
     this.mode   = mode;
 }