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,13 +39,22 @@ class Connection extends RawConnection {
|
||||||
if (!$this->isValid()) {
|
if (!$this->isValid()) {
|
||||||
throw new ConnectionException('Connection not valid');
|
throw new ConnectionException('Connection not valid');
|
||||||
}
|
}
|
||||||
$line = $this->readLine(); //first line is prompt
|
$promptLine = $this->readLine(); //first line is prompt
|
||||||
$this->checkConnectionError($line);
|
$this->checkConnectionError($promptLine);
|
||||||
|
|
||||||
$output = array();
|
$output = array();
|
||||||
$line = $this->readLine();
|
$line = $this->readLine();
|
||||||
if ($line === false) {
|
if ($line === false) {
|
||||||
throw new ConnectException('Unknown error');
|
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);
|
$length = mb_strlen(self::DELIMITER);
|
||||||
while (mb_substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter
|
while (mb_substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,15 @@ class RawConnection {
|
||||||
return stream_get_line($this->getOutputStream(), 4086, "\n");
|
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
|
* get all output until the process closes
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue