예제 #1
0
        /// <summary>
        /// 处理服务器套接字
        /// </summary>
        /// <param name="item">待处理的PollItem</param>
        private void HandleServerSocket(PollItem item)
        {
            //如果出错或者挂起,则关闭连接
            if ((item.Mode & (PollMode.PollError | PollMode.PollHangUp)) != 0)
            {
                poll.Unregister(server);
                server.Close();
            }

            //否则建立一个新的socket,然后让侦听中的插口去accept它,以后数据的读写应该在新的socket中进行。
            else
            {
                Socket newSocket = server.Accept();
                newSocket.Blocking = false;
                SingleSocket newSingleSocket = new SingleSocket(this, newSocket, handler);
                singleSocketDictionary[newSocket.Handle] = newSingleSocket;
                poll.Register(newSocket, PollMode.PollIn);
                handler.MakeExternalConnection(newSingleSocket);
            }
        }