private function readLineFromSocket(ApiClient $apiClient, HttpRequest $request, $socket, $maxNumberOfBytes) {
		stream_set_blocking($socket, false);
		$maxTime = $this->getStartTime() + $apiClient->getConnectionTimeout();
		$result = false;
		while ($maxTime >= time() && $result === false && !feof($socket)) {
			$tmp = fgets($socket, $maxNumberOfBytes);
			if ($tmp !== false && strlen($tmp) > 0) {
				$result = $tmp;
			} else {
				// Wait 100 milliseconds
				usleep(100 * 1000);
			}
		}
		stream_set_blocking($socket, true);

		if ($result !== false) {
			return $result;
		} else {
			throw new ConnectionException(null, $request->getLogToken(),
					'The remote server did not respond within ' . $apiClient->getConnectionTimeout() . ' seconds.');
		}
	}