/**
  * Sends a request over a communicator.
  * 
  * @param Communicator $com The communicator to send the request over.
  * @param Registry     $reg An optional registry to sync the request with.
  * 
  * @return int The number of bytes sent.
  * @see Client::sendSync()
  * @see Client::sendAsync()
  */
 public function send(Communicator $com, Registry $reg = null)
 {
     if (null !== $reg && (null != $this->getTag() || !$reg->isTaglessModeOwner())) {
         $originalTag = $this->getTag();
         $this->setTag($reg->getOwnershipTag() . $originalTag);
         $bytes = $this->send($com);
         $this->setTag($originalTag);
         return $bytes;
     }
     if ($com->getTransmitter()->isPersistent()) {
         $old = $com->getTransmitter()->lock(T\Stream::DIRECTION_SEND);
         $bytes = $this->_send($com);
         $com->getTransmitter()->lock($old, true);
         return $bytes;
     }
     return $this->_send($com);
 }
 public function testTaglessModePassing()
 {
     $com1 = new Communicator(\HOSTNAME, PORT, true);
     Client::login($com1, USERNAME, PASSWORD);
     $reg1 = new Registry('dummy');
     $com2 = new Communicator(\HOSTNAME, PORT, true);
     $reg2 = new Registry('dummy');
     $this->assertNotEquals($reg1->getOwnershipTag(), $reg2->getOwnershipTag());
     $pingRequest1 = new Request('/ping address=' . HOSTNAME, null, 'ping');
     $pingRequest1->send($com1, $reg1);
     $response1_1 = new Response($com1, false, null, null, $reg1);
     $cancelRequest = new Request('/cancel');
     $reg1->setTaglessMode(true);
     $cancelRequest->setArgument('tag', $reg1->getOwnershipTag() . 'ping');
     $cancelRequest->send($com1, $reg1);
     $pingRequest2 = new Request('/ping count=2 address=' . HOSTNAME, null, 'ping');
     $pingRequest2->send($com2, $reg2);
     $response2_1 = new Response($com2, false, null, null, $reg2);
     $response2_2 = new Response($com2, false, null, null, $reg2);
     $response2_3 = new Response($com2, false, null, null, $reg2);
     $reg1->setTaglessMode(false);
     $com1->close();
     $com2->close();
     $this->assertEquals(Response::TYPE_DATA, $response2_1->getType());
     $this->assertEquals(Response::TYPE_DATA, $response2_2->getType());
     $this->assertEquals(Response::TYPE_FINAL, $response2_3->getType());
     $response1_2 = new Response($com1, false, null, null, $reg1);
     $response1_3 = new Response($com1, false, null, null, $reg1);
     $this->assertEquals(Response::TYPE_DATA, $response1_1->getType());
     $this->assertEquals(Response::TYPE_ERROR, $response1_2->getType());
     $this->assertEquals(Response::TYPE_FINAL, $response1_3->getType());
     $reg1->close();
     $this->assertStringStartsWith('-1_', $reg2->getOwnershipTag());
 }