コード例 #1
0
ファイル: TcpClient.php プロジェクト: slrondon/MikrotikCenter
 /**
  * Sends a string or stream to the server.
  * 
  * Sends a string or stream to the server. If a seekable stream is
  * provided, it will be seeked back to the same position it was passed as,
  * regardless of the $offset parameter.
  * 
  * @param string|resource $contents The string or stream to send.
  * @param int             $offset   The offset from which to start sending.
  *     If a stream is provided, and this is set to NULL, sending will start
  *     from the current stream position.
  * @param int             $length   The maximum length to send. If omitted,
  *     the string/stream will be sent to its end.
  * 
  * @return int The number of bytes sent.
  */
 public function send($contents, $offset = null, $length = null)
 {
     if (false === ($previousState = $this->lock(self::DIRECTION_SEND)) && $this->persist) {
         throw $this->createException('Unable to obtain sending lock', 10);
     }
     try {
         $result = parent::send($contents, $offset, $length);
     } catch (E $e) {
         $this->lock($previousState, true);
         throw $e;
     }
     $this->lock($previousState, true);
     return $result;
 }