From 8ec8c153dd2a55ee8194892e10edd3aa3aaf40c6 Mon Sep 17 00:00:00 2001
From: Thomas Gelf <thomas@gelf.net>
Date: Sun, 16 Nov 2014 15:55:53 +0100
Subject: [PATCH] Livestatus\Connection: implement readLineFromSocket

We want to stream data in the near future, so reading line by line is
essential
---
 .../Icinga/Protocol/Livestatus/Connection.php | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/library/Icinga/Protocol/Livestatus/Connection.php b/library/Icinga/Protocol/Livestatus/Connection.php
index 3f6f8f325..c0082076f 100644
--- a/library/Icinga/Protocol/Livestatus/Connection.php
+++ b/library/Icinga/Protocol/Livestatus/Connection.php
@@ -248,6 +248,28 @@ class Connection
         return $buffer;
     }
 
+    protected function readLineFromSocket()
+    {
+        if ($this->bytesRead === $this->responseSize) {
+            return false;
+        }
+        $maxRowLength = 100 * 1024;
+        $row = socket_read($this->getConnection(), $maxRowLength, PHP_NORMAL_READ);
+        $this->bytesRead += strlen($row);
+
+        if ($row === false) {
+            $this->socketError('Failed to read next row from livestatus socket');
+        }
+        return $row;
+    }
+
+    /**
+     * Write given string to livestatus socket
+     *
+     * @param  string $data Data string to write to the socket
+     *
+     * @return boolean
+     */
     protected function writeToSocket($data)
     {
         $res = @socket_write($this->getConnection(), $data);