/// <summary> /// /// </summary> public SocketAsyncClient(IPEndPoint remoteEndPoint, int bufferSize, AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) { _remoteEndPoint = remoteEndPoint; _client = new Socket(addressFamily, socketType, protocolType); socketObject = new SocketObject(Guid.NewGuid(), _client); int maxConnection = 1; int numOfSaeaForRecSend = maxConnection * OpsToPreAlloc; _readWritePool = new SocketAsyncPool(numOfSaeaForRecSend); int numSize = numOfSaeaForRecSend * bufferSize; _bufferManager = new BufferManager(numSize, bufferSize); _bufferManager.InitBuffer(); _saeaProxy = new SocketAsyncEventArgsProxy(bufferSize); _saeaProxy.ReceiveCompleted += OnReceiveCompleted; _saeaProxy.SendCompleted += OnSendCompleted; _saeaProxy.ClosedHandle += OnSocketClosing; SocketAsyncEventArgs saea; for (int i = 0; i < numOfSaeaForRecSend; i++) { saea = _saeaProxy.CreateNewSaea(); _bufferManager.SetBuffer(saea); saea.UserToken = new DataToken(saea.Offset); _readWritePool.Push(saea); } }
private void Init() { for (int i = 0; i < _settings.MaxConnection; i++) { _acceptPool.Push(CreateAcceptEventArgs()); } _bufferManager.InitBuffer(); SocketAsyncEventArgs saea; for (int i = 0; i < _settings.NumOfSaeaForRecSend; i++) { saea = _saeaProxy.CreateNewSaea(); _bufferManager.SetBuffer(saea); saea.UserToken = new DataToken(saea.Offset); _readWritePool.Push(saea); } }