Ejemplo n.º 1
0
 public function writeString($value)
 {
     $len = TStringFuncFactory::create()->strlen($value);
     $result = $this->writeI32($len);
     if ($len) {
         $this->trans_->write($value, $len);
     }
     return $result + $len;
 }
Ejemplo n.º 2
0
 /**
  * Write to the socket.
  *
  * @param string $buf The data to write
  */
 public function write($buf)
 {
     $null = null;
     $write = array($this->handle_);
     // keep writing until all the data has been written
     while (TStringFuncFactory::create()->strlen($buf) > 0) {
         // wait for stream to become available for writing
         $writable = @stream_select($null, $write, $null, $this->sendTimeoutSec_, $this->sendTimeoutUsec_);
         if ($writable > 0) {
             // write buffer to stream
             $written = @stream_socket_sendto($this->handle_, $buf);
             if ($written === -1 || $written === false) {
                 throw new TTransportException('TSocket: Could not write ' . TStringFuncFactory::create()->strlen($buf) . ' bytes ' . $this->host_ . ':' . $this->port_);
             }
             // determine how much of the buffer is left to write
             $buf = TStringFuncFactory::create()->substr($buf, $written);
         } else {
             if ($writable === 0) {
                 throw new TTransportException('TSocket: timed out writing ' . TStringFuncFactory::create()->strlen($buf) . ' bytes from ' . $this->host_ . ':' . $this->port_);
             } else {
                 throw new TTransportException('TSocket: Could not write ' . TStringFuncFactory::create()->strlen($buf) . ' bytes ' . $this->host_ . ':' . $this->port_);
             }
         }
     }
 }