public function testSetDefaultCharset()
 {
     $com = new Communicator(HOSTNAME, PORT);
     $this->assertNull($com->getCharset(Communicator::CHARSET_REMOTE));
     $this->assertNull($com->getCharset(Communicator::CHARSET_LOCAL));
     Communicator::setDefaultCharset('windows-1251');
     $this->assertNull($com->getCharset(Communicator::CHARSET_REMOTE));
     $this->assertNull($com->getCharset(Communicator::CHARSET_LOCAL));
     $com = new Communicator(HOSTNAME, PORT);
     $this->assertEquals('windows-1251', $com->getCharset(Communicator::CHARSET_REMOTE));
     $this->assertEquals('windows-1251', $com->getCharset(Communicator::CHARSET_LOCAL));
     Communicator::setDefaultCharset(array(Communicator::CHARSET_REMOTE => 'ISO-8859-1', Communicator::CHARSET_LOCAL => 'ISO-8859-1'));
     $this->assertEquals('windows-1251', $com->getCharset(Communicator::CHARSET_REMOTE));
     $this->assertEquals('windows-1251', $com->getCharset(Communicator::CHARSET_LOCAL));
     $com = new Communicator(HOSTNAME, PORT);
     $this->assertEquals('ISO-8859-1', $com->getCharset(Communicator::CHARSET_REMOTE));
     $this->assertEquals('ISO-8859-1', $com->getCharset(Communicator::CHARSET_LOCAL));
     Communicator::setDefaultCharset(null);
     $this->assertEquals('ISO-8859-1', $com->getCharset(Communicator::CHARSET_REMOTE));
     $this->assertEquals('ISO-8859-1', $com->getCharset(Communicator::CHARSET_LOCAL));
     $com = new Communicator(HOSTNAME, PORT);
     $this->assertNull($com->getCharset(Communicator::CHARSET_REMOTE));
     $this->assertNull($com->getCharset(Communicator::CHARSET_LOCAL));
     Communicator::setDefaultCharset('windows-1251', Communicator::CHARSET_REMOTE);
     Communicator::setDefaultCharset('ISO-8859-1', Communicator::CHARSET_LOCAL);
     $this->assertNull($com->getCharset(Communicator::CHARSET_REMOTE));
     $this->assertNull($com->getCharset(Communicator::CHARSET_LOCAL));
     $com = new Communicator(HOSTNAME, PORT);
     $this->assertEquals('windows-1251', $com->getCharset(Communicator::CHARSET_REMOTE));
     $this->assertEquals('ISO-8859-1', $com->getCharset(Communicator::CHARSET_LOCAL));
     Communicator::setDefaultCharset(null);
 }
 /**
  * Login to a RouterOS connection.
  * 
  * @param Communicator $com      The communicator to attempt to login to.
  * @param string       $username The RouterOS username.
  * @param string       $password The RouterOS password.
  * @param int|null     $timeout  The time to wait for each response. NULL
  *     waits indefinetly.
  * 
  * @return bool TRUE on success, FALSE on failure.
  */
 public static function login(Communicator $com, $username, $password = '', $timeout = null)
 {
     if (null !== ($remoteCharset = $com->getCharset($com::CHARSET_REMOTE)) && null !== ($localCharset = $com->getCharset($com::CHARSET_LOCAL))) {
         $password = iconv($localCharset, $remoteCharset . '//IGNORE//TRANSLIT', $password);
     }
     $old = null;
     try {
         if ($com->getTransmitter()->isPersistent()) {
             $old = $com->getTransmitter()->lock(S::DIRECTION_ALL);
             $result = self::_login($com, $username, $password, $timeout);
             $com->getTransmitter()->lock($old, true);
             return $result;
         }
         return self::_login($com, $username, $password, $timeout);
     } catch (E $e) {
         if ($com->getTransmitter()->isPersistent() && null !== $old) {
             $com->getTransmitter()->lock($old, true);
         }
         throw $e instanceof NotSupportedException || $e instanceof UnexpectedValueException || !$com->getTransmitter()->isDataAwaiting() ? new SocketException('This is not a compatible RouterOS service', SocketException::CODE_SERVICE_INCOMPATIBLE, $e) : $e;
     }
 }