public function sendPacket(Packet $packet) { if (null === $packet->getFrom()) { $packet->setFrom($this->getPid()); } $this->getDriver()->write($packet); $destination = $this->isSlave() ? $this->getParentPid() : $this->getPid(); $signal = new Signal(SIGUSR1, $destination); $this->getSignalHandler()->send($signal); }
public function testSimple() { $this->assertSame('packet', $this->packet->getType()); $this->packet->setContent('foo'); $this->assertEquals('foo', $this->packet->getContent()); $connection = $this->getMock('\\Thruster\\Components\\InterProcessCommunication\\Connection'); $this->packet->setConnection($connection); $this->assertEquals($connection, $this->packet->getConnection()); $this->assertFalse($this->packet->isPropagationStopped()); $this->packet->stopPropagation(); $this->assertTrue($this->packet->isPropagationStopped()); }
/** * @inheritDoc */ public function __construct($content) { parent::__construct(static::NAME, Packet::MASTER, $content); }
/** * @param Packet $packet */ public function sendPacket(Packet $packet) { if (Packet::BROADCAST === $packet->getDestination()) { foreach ($this->getConnections() as $connection) { $connection->sendPacket($packet); } } else { foreach ($this->getConnections() as $connection) { if ($packet->getDestination() === $connection->getPid()) { $connection->sendPacket($packet); } } } }