improve error handling

This commit is contained in:
Robin Appelman 2021-03-02 19:06:04 +01:00
commit 26ec766638
3 changed files with 10 additions and 12 deletions

View file

@ -10,6 +10,7 @@ namespace Icewind\SMB\Wrapped;
use Icewind\SMB\Exception\AuthenticationException;
use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\ConnectionException;
use Icewind\SMB\Exception\ConnectionRefusedException;
use Icewind\SMB\Exception\InvalidHostException;
use Icewind\SMB\Exception\NoLoginServerException;
@ -31,7 +32,7 @@ class Connection extends RawConnection {
* @param string $input
*/
public function write($input) {
parent::write($input . PHP_EOL);
return parent::write($input . PHP_EOL);
}
/**
@ -43,7 +44,9 @@ class Connection extends RawConnection {
$promptLine = $this->readLine();
$this->parser->checkConnectionError($promptLine);
} while (!$this->isPrompt($promptLine));
$this->write('');
if ($this->write('') === false) {
throw new ConnectionRefusedException();
}
$this->readLine();
}

View file

@ -101,14 +101,9 @@ class RawConnection {
* @param string $input
*/
public function write($input) {
if (@fwrite($this->getInputStream(), $input) === false) {
$error = error_get_last();
if ($error && strpos($error['message'], "errno=32")) {
error_clear_last();
throw new ConnectionResetException();
}
}
$result = @fwrite($this->getInputStream(), $input);
fflush($this->getInputStream());
return $result;
}
/**

View file

@ -63,9 +63,6 @@ class Server extends AbstractServer {
if (isset($output[0])) {
$parser->checkConnectionError($output[0]);
}
// if (count($output) === 0) {
// throw new ConnectionRefusedException();
// }
// sometimes we get an empty line first
if (count($output) < 2) {
@ -75,6 +72,9 @@ class Server extends AbstractServer {
if (isset($output[0])) {
$parser->checkConnectionError($output[0]);
}
if (count($output) === 0) {
throw new ConnectionRefusedException();
}
$shareNames = $parser->parseListShares($output);