Esempio n. 1
0
 public TcpClientToken(int bufferSize, int bufferNumber) : base(bufferSize)
 {
     this._recBuffer    = new byte[bufferSize];
     this._bufferNumber = bufferNumber;
     _sendArgs          = new SocketEventArgPool(bufferNumber);
     _sendBuffMgr       = new SockArgBuffers(bufferNumber, bufferSize);
 }
Esempio n. 2
0
 public TcpServerToken(int maxConCount, int bufferSize) : base(bufferSize)
 {
     this._maxConCount = maxConCount;
     this.bufferSize   = bufferSize;
     _recBuffMgr       = new SockArgBuffers(maxConCount + _offsetNumber, bufferSize);
     _sendBuffMgr      = new SockArgBuffers(maxConCount + _offsetNumber, bufferSize);
     _sendArgs         = new SocketEventArgPool(maxConCount + _offsetNumber);
     _receiveArgs      = new SocketEventArgPool(maxConCount + _offsetNumber);
     _lockParam        = new LockParam();
     _countSema        = new Semaphore(maxConCount + _offsetNumber, maxConCount + _offsetNumber);
 }
Esempio n. 3
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);
     }
 }
Esempio n. 4
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);
     }
 }
Esempio n. 5
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);
        }
Esempio n. 6
0
 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);
     }
 }