mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
improve error handling
This commit is contained in:
parent
80a4edf0ef
commit
26ec766638
3 changed files with 10 additions and 12 deletions
|
|
@ -10,6 +10,7 @@ namespace Icewind\SMB\Wrapped;
|
||||||
use Icewind\SMB\Exception\AuthenticationException;
|
use Icewind\SMB\Exception\AuthenticationException;
|
||||||
use Icewind\SMB\Exception\ConnectException;
|
use Icewind\SMB\Exception\ConnectException;
|
||||||
use Icewind\SMB\Exception\ConnectionException;
|
use Icewind\SMB\Exception\ConnectionException;
|
||||||
|
use Icewind\SMB\Exception\ConnectionRefusedException;
|
||||||
use Icewind\SMB\Exception\InvalidHostException;
|
use Icewind\SMB\Exception\InvalidHostException;
|
||||||
use Icewind\SMB\Exception\NoLoginServerException;
|
use Icewind\SMB\Exception\NoLoginServerException;
|
||||||
|
|
||||||
|
|
@ -31,7 +32,7 @@ class Connection extends RawConnection {
|
||||||
* @param string $input
|
* @param string $input
|
||||||
*/
|
*/
|
||||||
public function write($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();
|
$promptLine = $this->readLine();
|
||||||
$this->parser->checkConnectionError($promptLine);
|
$this->parser->checkConnectionError($promptLine);
|
||||||
} while (!$this->isPrompt($promptLine));
|
} while (!$this->isPrompt($promptLine));
|
||||||
$this->write('');
|
if ($this->write('') === false) {
|
||||||
|
throw new ConnectionRefusedException();
|
||||||
|
}
|
||||||
$this->readLine();
|
$this->readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,14 +101,9 @@ class RawConnection {
|
||||||
* @param string $input
|
* @param string $input
|
||||||
*/
|
*/
|
||||||
public function write($input) {
|
public function write($input) {
|
||||||
if (@fwrite($this->getInputStream(), $input) === false) {
|
$result = @fwrite($this->getInputStream(), $input);
|
||||||
$error = error_get_last();
|
|
||||||
if ($error && strpos($error['message'], "errno=32")) {
|
|
||||||
error_clear_last();
|
|
||||||
throw new ConnectionResetException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fflush($this->getInputStream());
|
fflush($this->getInputStream());
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,6 @@ class Server extends AbstractServer {
|
||||||
if (isset($output[0])) {
|
if (isset($output[0])) {
|
||||||
$parser->checkConnectionError($output[0]);
|
$parser->checkConnectionError($output[0]);
|
||||||
}
|
}
|
||||||
// if (count($output) === 0) {
|
|
||||||
// throw new ConnectionRefusedException();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// sometimes we get an empty line first
|
// sometimes we get an empty line first
|
||||||
if (count($output) < 2) {
|
if (count($output) < 2) {
|
||||||
|
|
@ -75,6 +72,9 @@ class Server extends AbstractServer {
|
||||||
if (isset($output[0])) {
|
if (isset($output[0])) {
|
||||||
$parser->checkConnectionError($output[0]);
|
$parser->checkConnectionError($output[0]);
|
||||||
}
|
}
|
||||||
|
if (count($output) === 0) {
|
||||||
|
throw new ConnectionRefusedException();
|
||||||
|
}
|
||||||
|
|
||||||
$shareNames = $parser->parseListShares($output);
|
$shareNames = $parser->parseListShares($output);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue