mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Improved detection of connection errors
This commit is contained in:
parent
c92ae086f6
commit
a07a5ad2ec
2 changed files with 21 additions and 3 deletions
|
|
@ -39,14 +39,23 @@ class Connection extends RawConnection {
|
|||
if (!$this->isValid()) {
|
||||
throw new ConnectionException('Connection not valid');
|
||||
}
|
||||
$line = $this->readLine(); //first line is prompt
|
||||
$this->checkConnectionError($line);
|
||||
$promptLine = $this->readLine(); //first line is prompt
|
||||
$this->checkConnectionError($promptLine);
|
||||
|
||||
$output = array();
|
||||
$line = $this->readLine();
|
||||
if ($line === false) {
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
$length = mb_strlen(self::DELIMITER);
|
||||
while (mb_substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter
|
||||
$output[] .= $line;
|
||||
|
|
|
|||
|
|
@ -94,6 +94,15 @@ class RawConnection {
|
|||
return stream_get_line($this->getOutputStream(), 4086, "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* read a line of output
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function readError() {
|
||||
return trim(stream_get_line($this->getErrorStream(), 4086));
|
||||
}
|
||||
|
||||
/**
|
||||
* get all output until the process closes
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue