mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
factor out some error handling
This commit is contained in:
parent
e1b943bb8c
commit
11023c007e
1 changed files with 18 additions and 10 deletions
|
|
@ -46,16 +46,7 @@ class Connection extends RawConnection {
|
||||||
$output = array();
|
$output = array();
|
||||||
$line = $this->readLine();
|
$line = $this->readLine();
|
||||||
if ($line === false) {
|
if ($line === false) {
|
||||||
if ($promptLine) { //maybe we have some error we missed on the previous line
|
$this->unknownError($promptLine);
|
||||||
throw new ConnectException('Unknown error (' . $promptLine . ')');
|
|
||||||
} else {
|
|
||||||
$error = $this->readError(); // maybe something on stderr
|
|
||||||
if ($error) {
|
|
||||||
throw new ConnectException('Unknown error (' . $error . ')');
|
|
||||||
} else {
|
|
||||||
throw new ConnectException('Unknown error');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$length = mb_strlen(self::DELIMITER);
|
$length = mb_strlen(self::DELIMITER);
|
||||||
while (mb_substr($line, 0, $length) !== self::DELIMITER && $line !== false) { //next prompt functions as delimiter
|
while (mb_substr($line, 0, $length) !== self::DELIMITER && $line !== false) { //next prompt functions as delimiter
|
||||||
|
|
@ -72,6 +63,23 @@ class Connection extends RawConnection {
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $promptLine (optional) prompt line that might contain some info about the error
|
||||||
|
* @throws ConnectException
|
||||||
|
*/
|
||||||
|
private function unknownError($promptLine = '') {
|
||||||
|
if ($promptLine) { //maybe we have some error we missed on the previous line
|
||||||
|
throw new ConnectException('Unknown error (' . $promptLine . ')');
|
||||||
|
} else {
|
||||||
|
$error = $this->readError(); // maybe something on stderr
|
||||||
|
if ($error) {
|
||||||
|
throw new ConnectException('Unknown error (' . $error . ')');
|
||||||
|
} else {
|
||||||
|
throw new ConnectException('Unknown error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the first line holds a connection failure
|
* check if the first line holds a connection failure
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue