//
        // Opens the socket and links as active
        //
        public async Task ConnectAsync(SocketAddress endpoint, CancellationToken ct)
        {
            if (_cleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }
            if (IsListening)
            {
                throw new InvalidOperationException("Socket is listening");
            }
            try {
                await _internal.ConnectAsync(endpoint, ct).ConfigureAwait(false);

                Connected = true;
                IsBound   = true;
            }
            catch (OperationCanceledException) {
                throw;
            }
            catch (Exception e) {
                throw SocketException.Create($"Exception connecting to {endpoint.ToString()}", e);
            }
        }
Ejemplo n.º 2
0
        public async Task Check(ProxyDto dto)
        {
            var proxyStatus = await _socket.ConnectAsync(dto.IP, dto.Port, 5000);

            if (proxyStatus.Connected)
            {
                await IncreaseScoreAsync(dto, 1);

                await _randomPool.AddAsync(dto.IP, dto.Port);
            }
            else
            {
                if (dto.Score <= 1)
                {
                    await DeleteProxyAsync(dto);

                    await _randomPool.RemoveAsync(dto.IP, dto.Port);
                }
                else
                {
                    await IncreaseScoreAsync(dto, -1);

                    await _randomPool.AddAsync(dto.IP, dto.Port);
                }
            }
        }