Esempio n. 1
0
extern "C" void AsebaSendBuffer(AsebaVMState *vm, const uint8* data, uint16 length)
{
	Enki::AsebaMarxbot& marxBot = *asebaSocketMaps[vm];
	Dashel::Stream* stream = marxBot.stream;
	if (!stream)
		return;
	
	// send to stream
	try
	{
		uint16 temp;
		temp = bswap16(length - 2);
		stream->write(&temp, 2);
		temp = bswap16(vm->nodeId);
		stream->write(&temp, 2);
		stream->write(data, length);
		stream->flush();

		// push to other nodes
		for (size_t i = 0; i < marxBot.modules.size(); ++i)
		{
			Enki::AsebaMarxbot::Module& module = *(marxBot.modules[i]);
			if (&(module.vm) != vm) 
			{
				module.events.push_back(Enki::AsebaMarxbot::Event(vm->nodeId, data, length));
				AsebaProcessIncomingEvents(&(module.vm));
			}
		}
	}
	catch (Dashel::DashelException e)
	{
		std::cerr << "Cannot write to socket: " << stream->getFailReason() << std::endl;
	}
}
Esempio n. 2
0
extern "C" void AsebaSendBuffer(AsebaVMState *vm, const uint8* data, uint16 length)
{
	Dashel::Stream* stream = node.stream;
	if (stream)
	{
		try
		{
			uint16 temp;
			temp = bswap16(length - 2);
			stream->write(&temp, 2);
			temp = bswap16(vm->nodeId);
			stream->write(&temp, 2);
			stream->write(data, length);
			stream->flush();
		}
		catch (Dashel::DashelException e)
		{
			std::cerr << "Cannot write to socket: " << stream->getFailReason() << std::endl;
		}
	}
}