Esempio n. 1
0
        public AsyncSocketClientUDP(int _maxSize, int _maxConnnections, ICommonLog _logTool)
        {
            m_readWritePool   = new SocketAsyncEventArgsPool <AsyncClientToken>();
            m_maxConnnections = _maxConnnections;
            m_maxSize         = _maxSize;
            LogTool           = _logTool;
            m_bufferManager   = BufferManager.CreateBufferManager(m_maxConnnections * m_maxSize, m_maxSize);

            for (int i = 0; i < _maxConnnections; i++)
            {
                AsyncClientToken asyncClientToken = new AsyncClientToken();
                asyncClientToken.Buffer = m_bufferManager.TakeBuffer(m_maxSize);
                asyncClientToken.Socket = new Socket(SocketType.Dgram, ProtocolType.Udp);
                m_readWritePool.Push(asyncClientToken);
            }

            m_maxNumberAcceptedClients = new Semaphore(m_maxConnnections, m_maxConnnections);
        }
        public AsyncSocketListener(int _maxSize, int _maxConnnections, ICommonLog _logTool)
        {
            m_readWritePool   = new SocketAsyncEventArgsPool <SocketAsyncEventArgs>();
            m_maxConnnections = _maxConnnections;
            m_maxSize         = _maxSize;
            LogTool           = _logTool;

            //m_bufferManager = BufferManager.CreateBufferManager(m_maxConnnections * m_maxSize * opsToPreAlloc, m_maxSize);
            m_bufferManager = BufferManager.CreateBufferManager(m_maxConnnections * m_maxSize, m_maxSize);

            for (int i = 0; i < m_maxConnnections; i++)
            {
                SocketAsyncEventArgs socketAsyncEventArg = new SocketAsyncEventArgs();
                socketAsyncEventArg.UserToken  = new T();
                socketAsyncEventArg.Completed += new EventHandler <SocketAsyncEventArgs>(IO_Completed);
                socketAsyncEventArg.SetBuffer(m_bufferManager.TakeBuffer(m_maxSize), 0, m_maxSize);
                m_readWritePool.Push(socketAsyncEventArg);
            }

            m_maxNumberAcceptedClients = new Semaphore(m_maxConnnections, m_maxConnnections);
        }