Exemple #1
0
        private void InitArgs()
        {
            _receiveArgs.Clear();
            _sendArgs.Clear();
            _sendBuffMgr.FreeBuffer();
            _recBuffMgr.FreeBuffer();
            for (int i = 0; i < _maxConCount + _offsetNumber; i++)
            {
                SocketAsyncEventArgs senArg = new SocketAsyncEventArgs()
                {
                    DisconnectReuseSocket = true,
                    SocketError           = SocketError.NotInitialized
                };
                senArg.Completed += IOCompleted;
                senArg.UserToken  = new SocketToken(i);
                _sendArgs.Set(senArg);
                _sendBuffMgr.SetBuffer(senArg);

                SocketAsyncEventArgs recArg = new SocketAsyncEventArgs()
                {
                    DisconnectReuseSocket = true,
                    SocketError           = SocketError.SocketError
                };
                recArg.Completed += IOCompleted;
                SocketToken token = new SocketToken(i)
                {
                    arg = recArg
                };
                recArg.UserToken = token;
                _recBuffMgr.SetBuffer(recArg);
                _receiveArgs.Set(recArg);
            }
        }
Exemple #2
0
 public SocketSend(Socket sock, int maxCount, int bufferSize = 4096) : base(bufferSize)
 {
     base._sock = sock;
     sendArgs   = new SocketEventArgPool(maxCount);
     sendBuff   = new SockArgBuffers(maxCount, bufferSize);
     for (int i = 0; i < maxCount; ++i)
     {
         SocketAsyncEventArgs socketArgs = new SocketAsyncEventArgs();
         socketArgs.UserToken  = sock;
         socketArgs.Completed += SendCompleted;
         sendBuff.SetBuffer(socketArgs);
         sendArgs.Set(socketArgs);
     }
 }
Exemple #3
0
 public SocketSend(int maxCount, int bufferSize = 4096) : base(bufferSize)
 {
     _sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
     _sock.ReceiveTimeout = _receiveTimeout;
     _sock.SendTimeout    = _sendTimeout;
     sendArgs             = new SocketEventArgPool(maxCount);
     sendBuff             = new SockArgBuffers(maxCount, bufferSize);
     for (int i = 0; i < maxCount; ++i)
     {
         SocketAsyncEventArgs socketArgs = new SocketAsyncEventArgs();
         socketArgs.UserToken  = _sock;
         socketArgs.Completed += SendCompleted;
         sendBuff.SetBuffer(socketArgs);
         sendArgs.Set(socketArgs);
     }
 }
Exemple #4
0
        public bool Connect(int port, string ip)
        {
            Close();
            CreateUdpSocket(port, IPAddress.Parse(ip));
            _sendArgs = new SocketEventArgPool(_maxConn);
            _sendBuff = new SockArgBuffers(_maxConn, _recBufferSize);
            for (int i = 0; i < _maxConn; ++i)
            {
                SocketAsyncEventArgs sendArg = new SocketAsyncEventArgs();
                sendArg.Completed += IOCompleted;

                sendArg.UserToken = _sock;
                _sendBuff.SetBuffer(sendArg);
                _sendArgs.Set(sendArg);
            }
            return(true);
        }
 private void InitializePool(int bufferNumber)
 {
     _sendArgs.Clear();
     _sendBuffMgr.Clear();
     _sendBuffMgr.FreeBuffer();
     _sendBuffMgr = new SockArgBuffers(bufferNumber, bufferSize);
     _sendArgs    = new SocketEventArgPool(bufferNumber);
     for (int i = 0; i < bufferNumber; ++i)
     {
         SocketAsyncEventArgs tArgs = new SocketAsyncEventArgs()
         {
             DisconnectReuseSocket = true
         };
         tArgs.Completed += IOCompleted;
         tArgs.UserToken  = new SocketToken(i)
         {
             sock    = sock,
             tokenId = i
         };
         _sendBuffMgr.SetBuffer(tArgs);
         _sendArgs.Set(tArgs);
     }
 }