Permalink
Browse files

Added a new exception code and message to separate socket initializat…

…ion problems from connection problems;

Moved TcpServerConnection's exception codes.
  • Loading branch information...
1 parent 80ec937 commit 3f653c98ff3ae10b876a1a30b3ed642e389e3928 @boenrobot boenrobot committed Aug 19, 2012
@@ -43,7 +43,7 @@ class TcpClient extends NetworkStream
/**
* @var int The error code of the last error on the socket.
*/
- protected $error_no = null;
+ protected $error_no = 0;
/**
* @var string The error message of the last error on the socket.
@@ -112,7 +112,10 @@ public function __construct($host, $port, $persist = false,
)
);
} catch (\Exception $e) {
- throw $this->createException('Failed to initialize socket.', 7);
+ if (0 === $this->error_no) {
+ throw $this->createException('Failed to initialize socket.', 7);
+ }
+ throw $this->createException('Failed to connect with socket.', 8);
}
if ($persist) {
$this->shmHandler = SHM::factory(
@@ -57,7 +57,7 @@ class TcpServerConnection extends NetworkStream
public function __construct($server, $timeout = null)
{
if (!self::isStream($server)) {
- throw $this->createException('Invalid server supplied.', 8);
+ throw $this->createException('Invalid server supplied.', 9);
}
$timeout
= null == $timeout ? ini_get('default_socket_timeout') : $timeout;
@@ -78,7 +78,9 @@ public function __construct($server, $timeout = null)
}
$this->peerIP = $ipString;
} catch (Exception $e) {
- throw $this->createException('Failed to initialize connection.', 9);
+ throw $this->createException(
+ 'Failed to initialize connection.', 10
+ );
}
}
View
@@ -127,7 +127,7 @@ public function testSilence()
$this->fail('Client creation had to fail.');
} catch(SocketException $e)
{
- $this->assertEquals(7, $e->getCode(), 'Improper exception code.');
+ $this->assertEquals(8, $e->getCode(), 'Improper exception code.');
$this->assertEquals(
10061, $e->getSocketErrorNumber(), 'Improper exception code.'
);
@@ -137,21 +137,35 @@ public function testSilence()
$this->fail('Client creation had to fail.');
} catch(SocketException $e)
{
- $this->assertEquals(7, $e->getCode(), 'Improper exception code.');
+ $this->assertEquals(8, $e->getCode(), 'Improper exception code.');
$this->assertEquals(
10061, $e->getSocketErrorNumber(), 'Improper exception code.'
);
}
}
+ public function testInvalidClient()
+ {
+ try {
+ new C('@', REMOTE_PORT);
+ $this->fail('Client creation had to fail.');
+ } catch(SocketException $e)
+ {
+ $this->assertEquals(7, $e->getCode(), 'Improper exception code.');
+ $this->assertEquals(
+ 0, $e->getSocketErrorNumber(), 'Improper exception code.'
+ );
+ }
+ }
+
public function testInvalidServer()
{
try {
new SC('not a server', 1/*h*/ * 60/*m*/ * 60/*s*/);
$this->fail('Server creation had to fail.');
} catch(SocketException $e)
{
- $this->assertEquals(8, $e->getCode(), 'Improper exception code.');
+ $this->assertEquals(9, $e->getCode(), 'Improper exception code.');
}
}
@@ -167,7 +181,7 @@ public function testServerConnectionTimeout()
$this->fail('Server creation had to fail.');
} catch(SocketException $e)
{
- $this->assertEquals(9, $e->getCode(), 'Improper exception code.');
+ $this->assertEquals(10, $e->getCode(), 'Improper exception code.');
}
}
}

0 comments on commit 3f653c9

Please sign in to comment.