Esempio n. 1
0
 /**
  * Performs a blocking write
  */
 function write($buff)
 {
     if (!$this->select(self::BLOCK_TIMEOUT, 0, self::WRITE_SELECT)) {
         trigger_error('Socket select failed for write (socket err: "' . $this->strError() . ')', E_USER_WARNING);
         return 0;
     }
     $bw = 0;
     $contentLength = strlen($buff);
     while (true) {
         if (Connection::DEBUG) {
             echo "\n<write>\n";
             echo wire\Hexdump::hexdump($buff);
         }
         if (($tmp = socket_write($this->sock, $buff)) === false) {
             throw new \Exception(sprintf("Socket write failed: %s", $this->strError()), 7854);
         }
         $bw += $tmp;
         if ($bw < $contentLength) {
             $buff = substr($buff, $bw);
         } else {
             break;
         }
     }
     return $bw;
 }
Esempio n. 2
0
 function write($buff)
 {
     if (!$this->select(self::BLOCK_TIMEOUT, 0, self::WRITE_SELECT)) {
         trigger_error('StreamSocket select failed for write (stream socket err: "' . $this->strError() . ')', E_USER_WARNING);
         return 0;
     }
     $bw = 0;
     $contentLength = strlen($buff);
     if ($contentLength == 0) {
         return 0;
     }
     while (true) {
         if (Connection::DEBUG) {
             echo "\n<write>\n";
             echo wire\Hexdump::hexdump($buff);
         }
         if (($tmp = fwrite($this->sock, $buff)) === false) {
             $this->errFlag |= 2;
             throw new \Exception(sprintf("\nStream write failed (error): %s\n", $this->strError()), 7854);
         } else {
             if ($tmp === 0) {
                 throw new \Exception(sprintf("\nStream write failed (zero bytes written): %s\n", $this->strError()), 7855);
             }
         }
         $bw += $tmp;
         if ($bw < $contentLength) {
             $buff = substr($buff, $bw);
         } else {
             break;
         }
     }
     fflush($this->sock);
     return $bw;
 }