예제 #1
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;
		}
	}
예제 #2
0
	bt::Uint32 UTPSocket::bytesAvailable() const
	{
		Connection::Ptr ptr = conn.toStrongRef();
		if (ptr)
			return ptr->bytesAvailable();
		else
			return 0;
	}