Beispiel #1
0
void SctpSocket::OnException()
{
	if (Connecting())
	{
#ifdef ENABLE_SOCKS4
		if (Socks4())
			OnSocks4ConnectFailed();
		else
#endif
		if (GetConnectionRetry() == -1 ||
			(GetConnectionRetry() &&
			 GetConnectionRetries() < GetConnectionRetry() ))
		{
			// even though the connection failed at once, only retry after
			// the connection timeout
			// should we even try to connect again, when CheckConnect returns
			// false it's because of a connection error - not a timeout...
		}
		else
		{
			SetConnecting(false); // tnx snibbe
			SetCloseAndDelete();
			OnConnectFailed();
		}
		return;
	}
	// %! exception doesn't always mean something bad happened, this code should be reworked
	// errno valid here?
	int err = SoError();
	Handler().LogError(this, "exception on select", err, StrError(err), LOG_LEVEL_FATAL);
	SetCloseAndDelete();
}
Beispiel #2
0
void HttpGetSocket::DoConnect(const std::string& host, unsigned short port)
{
	if (!Open(host, port))
	{
		if (!Connecting())
		{
			Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL);
			SetCloseAndDelete();
		}
	}
}
Beispiel #3
0
HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& url_in,const std::string& to_file) : HttpClientSocket(h, url_in)
{
	if (to_file.size())
	{
		SetFilename(to_file);
	}
	if (!Open(GetUrlHost(),GetUrlPort()))
	{
		if (!Connecting())
		{
			Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL);
			SetCloseAndDelete();
		}
	}
}
Beispiel #4
0
HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& host,port_t port,const std::string& url,const std::string& to_file) : HttpClientSocket(h)
{
	SetUrl(url);
	if (to_file.size())
	{
		SetFilename(to_file);
	}
	if (!Open(host, port))
	{
		if (!Connecting())
		{
			Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL);
			SetCloseAndDelete();
		}
	}
}
Beispiel #5
0
void SctpSocket::OnWrite()
{
	if (Connecting())
	{
		int err = SoError();

		// don't reset connecting flag on error here, we want the OnConnectFailed timeout later on
		/// \todo add to read fd_set here
		if (!err) // ok
		{
			Set(!IsDisableRead(), false);
			SetConnecting(false);
			SetCallOnConnect();
			return;
		}
		Handler().LogError(this, "sctp: connect failed", err, StrError(err), LOG_LEVEL_FATAL);
		Set(false, false); // no more monitoring because connection failed

		// failed
#ifdef ENABLE_SOCKS4
		if (Socks4())
		{
			OnSocks4ConnectFailed();
			return;
		}
#endif
		if (GetConnectionRetry() == -1 ||
			(GetConnectionRetry() && GetConnectionRetries() < GetConnectionRetry()) )
		{
			// even though the connection failed at once, only retry after
			// the connection timeout.
			// should we even try to connect again, when CheckConnect returns
			// false it's because of a connection error - not a timeout...
			return;
		}
		SetConnecting(false);
		SetCloseAndDelete( true );
		/// \todo state reason why connect failed
		OnConnectFailed();
		return;
	}
}
Beispiel #6
0
bool RedisClient::TryConnecting(){
    static std::atomic<int> curr_retry(0);
    int zero = 0;
    if( ! std::atomic_compare_exchange_strong(&curr_retry, &zero,1) ){
        return false;
    }
    do{
        LOGT("TryConnecting : try connecting ... "<<curr_retry);
        if(Connecting())
            curr_retry  = 0;
        else{
            curr_retry++;
            if(curr_retry == 3) { 
                LOGE("Fatal Error : can't connect to redis "<< m_ip << " : " <<  m_port);
                return false;
            }
        }
    }while(curr_retry);
    return true;
}
Beispiel #7
0
bool StreamSocket::Ready()
{
	if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete())
		return true;
	return false;
}