Beispiel #1
0
	bool UTPSocket::connectTo(const net::Address& addr)
	{
		if (!bt::Globals::instance().isUTPEnabled())
			return false;

		UTPServer & srv = bt::Globals::instance().getUTPServer();
		reset();

		conn = srv.connectTo(addr);
		Connection::Ptr ptr = conn.toStrongRef();
		if (!ptr)
			return false;

		m_state = CONNECTING;
		ptr->setBlocking(blocking);
		if (blocking)
		{
			bool ret = ptr->waitUntilConnected();
			if (ret)
				m_state = CONNECTED;

			return ret;
		}

		return ptr->connectionState() == CS_CONNECTED;
	}
Beispiel #2
0
	bool UTPSocket::ready(const net::Poll* p, net::Poll::Mode mode) const
	{
		Q_UNUSED(p);
		Connection::Ptr ptr = conn.toStrongRef();
		if (!ptr)
			return false;

		if (mode == net::Poll::OUTPUT)
		{
			if (polled_for_writing)
			{
				polled_for_writing = false;
				return ptr->isWriteable();
			}
		}
		else
		{
			if (polled_for_reading)
			{
				polled_for_reading = false;
				return bytesAvailable() > 0 || ptr->connectionState() == CS_CLOSED;
			}
		}

		return false;
	}
Beispiel #3
0
	int UTPSocket::recv(bt::Uint8* buf, int max_len)
	{
		Connection::Ptr ptr = conn.toStrongRef();
		if (!ptr || ptr->connectionState() == CS_CLOSED)
			return 0;

		try
		{
			if (ptr->bytesAvailable() == 0)
			{
				if (blocking)
				{
					if (ptr->waitForData())
						return ptr->recv(buf, max_len);
					else
						return 0; // connection should be closed now
				}
				else
					return -1; // No data ready and not blocking so return -1
			}
			else
				return ptr->recv(buf, max_len);
		}
		catch (Connection::TransmissionError & err)
		{
			close();
			return -1;
		}
	}
Beispiel #4
0
	bool UTPSocket::connectSuccesFull()
	{
		Connection::Ptr ptr = conn.toStrongRef();
		if (ptr && ptr->connectionState() == CS_CONNECTED)
		{
			setRemoteAddress(ptr->remoteAddress());
			m_state = CONNECTED;
			return true;
		}
		else
			return false;
	}
Beispiel #5
0
	void UTPSocket::prepare(net::Poll* p, net::Poll::Mode mode)
	{
		Connection::Ptr ptr = conn.toStrongRef();
		if (ptr && ptr->connectionState() != CS_CLOSED)
		{
			UTPServer & srv = bt::Globals::instance().getUTPServer();
			srv.preparePolling(p, mode, ptr);
			if (mode == net::Poll::OUTPUT)
				polled_for_writing = true;
			else
				polled_for_reading = true;
		}
	}
Beispiel #6
0
	bool UTPSocket::ok() const
	{
		Connection::Ptr ptr = conn.toStrongRef();
		return ptr && ptr->connectionState() != CS_CLOSED;
	}