Example #1
0
bool SerialPort::waitForData(const Misc::Time& timeout) const
	{
	/* Check if there is unread data in the buffer: */
	if(getUnreadDataSize()>0)
		return true;
	
	/* Wait for data on the socket and return whether data is available: */
	Misc::FdSet readFds(fd);
	return Misc::pselect(&readFds,0,0,timeout)>=0&&readFds.isSet(fd);
	}
Example #2
0
bool TCPPipeSlave::waitForData(const Misc::Time& timeout) const
	{
	/* Check if there is unread data in the buffer: */
	if(getUnreadDataSize()>0)
		return true;
	
	/* Read the status packet from the master node: */
	Packet* statusPacket=multiplexer->receivePacket(pipeId);
	Packet::Reader reader(statusPacket);
	int result=reader.read<int>();
	multiplexer->deletePacket(statusPacket);
	
	return result!=0;
	}
Example #3
0
bool TCPPipeMaster::waitForData(const Misc::Time& timeout) const
	{
	/* Check if there is unread data in the buffer: */
	if(getUnreadDataSize()>0)
		return true;
	
	/* Wait for data on the socket and return whether data is available: */
	Misc::FdSet readFds(fd);
	bool result=Misc::pselect(&readFds,0,0,timeout)>=0&&readFds.isSet(fd);
	
	/* Send a status message to the slaves: */
	Packet* statusPacket=multiplexer->newPacket();
	{
	Packet::Writer writer(statusPacket);
	writer.write<int>(result?1:0);
	}
	multiplexer->sendPacket(pipeId,statusPacket);
	
	return result;
	}
Example #4
0
bool TCPPipeSlave::waitForData(const Misc::Time& timeout) const
	{
	if(isReadCoupled())
		{
		/* Check if there is unread data in the buffer: */
		if(getUnreadDataSize()>0)
			return true;
		
		/* Read the status packet from the master node: */
		Packet* statusPacket=multiplexer->receivePacket(pipeId);
		Packet::Reader reader(statusPacket);
		int result=reader.read<int>();
		multiplexer->deletePacket(statusPacket);
		
		return result!=0;
		}
	else
		{
		/* Return no new data; slave shouldn't be reading in decoupled state: */
		return false;
		}
	}