aboutsummaryrefslogtreecommitdiff
path: root/src/callnotifier/Source/Remote.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-08-08 06:42:59 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-08-08 06:42:59 +0200
commita74388255ced48e9dac0490acc76b782f74cc2c8 (patch)
tree757cbf7c38f32dd923ee5876f7ca5cfdb8f692fb /src/callnotifier/Source/Remote.php
parentf76b792464115de91324d1c74c692d8c5b4a34a8 (diff)
downloadauerswald-callnotifier-a74388255ced48e9dac0490acc76b782f74cc2c8.tar.gz
auerswald-callnotifier-a74388255ced48e9dac0490acc76b782f74cc2c8.zip
throw exception when connection to switchboard cannot be established
Diffstat (limited to 'src/callnotifier/Source/Remote.php')
-rw-r--r--src/callnotifier/Source/Remote.php22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/callnotifier/Source/Remote.php b/src/callnotifier/Source/Remote.php
index 36e468d..39b042c 100644
--- a/src/callnotifier/Source/Remote.php
+++ b/src/callnotifier/Source/Remote.php
@@ -21,20 +21,24 @@ class Source_Remote
public function connect($ip, $port)
{
+ if ($ip == '') {
+ throw new \Exception('No remote IP or hostname given.');
+ }
+
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
- echo "socket_create() failed: reason: "
- . socket_strerror(socket_last_error()) . "\n";
- } else {
- echo "OK.\n";
+ throw new \Exception(
+ 'socket_create() failed: reason: '
+ . socket_strerror(socket_last_error())
+ );
}
- echo "Attempting to connect to '$ip' on port '$port'...";
+ //echo "Attempting to connect to '$ip' on port '$port'...";
$result = socket_connect($socket, $ip, $port);
if ($result === false) {
- echo "socket_connect() failed.\nReason: ($result) "
- . socket_strerror(socket_last_error($socket)) . "\n";
- } else {
- echo "OK.\n";
+ throw new \Exception(
+ "socket_connect() failed. Reason: "
+ . socket_strerror(socket_last_error($socket))
+ );
}
$this->socket = $socket;