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); }
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); }
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); } }
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); } }
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); } }