Esempio n. 1
0
void NetworkObserver::timerEvent(QTimerEvent*)
{
	if (is_connection_available())
	{
		if (!_isConnected)
		{
			//if(!_prevstate)
			//{
				LOG_DEBUG("Connection is up");
				_isConnected = true;
				connectionIsUpEvent(*this);
			//}
			//_prevstate--;
		}
	}
	else
	{
		if (_isConnected)
		{
			LOG_DEBUG("Connection is down");
			_isConnected = false;
			connectionIsDownEvent(*this);
			//_prevstate = RETRIES;
		}
	}
}
Esempio n. 2
0
Ref<StreamPeerTCP> TCPServerPosix::take_connection() {

	if (!is_connection_available()) {
		return Ref<StreamPeerTCP>();
	};

	struct sockaddr_storage their_addr;
	socklen_t size = sizeof(their_addr);
	int fd = accept(listen_sockfd, (struct sockaddr *)&their_addr, &size);
	ERR_FAIL_COND_V(fd == -1, Ref<StreamPeerTCP>());
#ifndef NO_FCNTL
	fcntl(fd, F_SETFL, O_NONBLOCK);
#else
	int bval = 1;
	ioctl(fd, FIONBIO, &bval);
#endif

	Ref<StreamPeerTCPPosix> conn = memnew(StreamPeerTCPPosix);
	IP_Address ip;

	int port;
	_set_ip_addr_port(ip, port, &their_addr);

	conn->set_socket(fd, ip, port, sock_type);

	return conn;
};
Esempio n. 3
0
bool NetworkObserver::isConnected() 
{
	//VOXOX CHANGE by Rolando - 2009.07.27 - modified to not let assign value to variable "_isConnected", this variable should change only on method "timerEvent()"
	//because otherwise it will never trigger the event "connectionIsDownEvent" when a connection is down.
	/*_isConnected = (is_connection_available() ? true : false);
	return _isConnected ; */

	return is_connection_available();//VOXOX CHANGE by Rolando - 2009.07.27 
}
Esempio n. 4
0
NetworkObserver::NetworkObserver() 
{
	//_prevstate = 0;
	_isConnected = (is_connection_available() ? true : false);
	//_timer.timeoutEvent += boost::bind(&NetworkObserver::timeoutEventHandler, this);

	//_timer.start(0, 500, 0);
	_idTimer = startTimer(15000);	//VOXOX - JRT - 2009.07.09 
}
Esempio n. 5
0
Ref<StreamPeerTCP> TCP_Server::take_connection() {

	Ref<StreamPeerTCP> conn;
	if (!is_connection_available()) {
		return conn;
	}

	Ref<NetSocket> ns;
	IP_Address ip;
	uint16_t port = 0;
	ns = _sock->accept(ip, port);
	if (!ns.is_valid())
		return conn;

	conn = Ref<StreamPeerTCP>(memnew(StreamPeerTCP));
	conn->accept_socket(ns, ip, port);
	return conn;
}
Esempio n. 6
0
Ref<StreamPeerTCP> TCPServerWinsock::take_connection() {

    if (!is_connection_available()) {
        return NULL;
    };

    struct sockaddr_in their_addr;
    int sin_size = sizeof(their_addr);
    int fd = accept(listen_sockfd, (struct sockaddr *)&their_addr, &sin_size);
    ERR_FAIL_COND_V(fd == INVALID_SOCKET, NULL);

    Ref<StreamPeerWinsock> conn = memnew(StreamPeerWinsock);
    IP_Address ip;
    ip.host = (uint32_t)their_addr.sin_addr.s_addr;

    conn->set_socket(fd, ip, ntohs(their_addr.sin_port));

    return conn;
};