1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Async sockets |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015-2017, Efimov Evgenij <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the MIT license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
namespace AsyncSockets\Event; |
11
|
|
|
|
12
|
|
|
use AsyncSockets\RequestExecutor\RequestExecutorInterface; |
13
|
|
|
use AsyncSockets\Socket\SocketInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class AcceptEvent |
17
|
|
|
*/ |
18
|
|
|
class AcceptEvent extends Event |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Client sockets |
22
|
|
|
* |
23
|
|
|
* @var SocketInterface |
24
|
|
|
*/ |
25
|
|
|
private $clientSocket; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Remote address |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $remoteAddress; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor |
36
|
|
|
* |
37
|
|
|
* @param RequestExecutorInterface $executor Request executor object |
38
|
|
|
* @param SocketInterface $serverSocket Server socket for this request |
39
|
|
|
* @param mixed $context Any optional user data for event |
40
|
|
|
* @param SocketInterface $clientSocket Accepted client socket |
41
|
|
|
* @param string $remoteAddress Remote address |
42
|
|
|
*/ |
43
|
7 |
|
public function __construct( |
44
|
|
|
RequestExecutorInterface $executor, |
45
|
|
|
SocketInterface $serverSocket, |
46
|
|
|
$context, |
47
|
|
|
SocketInterface $clientSocket, |
48
|
|
|
$remoteAddress |
49
|
|
|
) { |
50
|
7 |
|
parent::__construct($executor, $serverSocket, $context, EventType::ACCEPT); |
51
|
7 |
|
$this->clientSocket = $clientSocket; |
52
|
7 |
|
$this->remoteAddress = $remoteAddress; |
53
|
7 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return accepted client socket |
57
|
|
|
* |
58
|
|
|
* @return SocketInterface |
59
|
|
|
*/ |
60
|
1 |
|
public function getClientSocket() |
61
|
|
|
{ |
62
|
1 |
|
return $this->clientSocket; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Return remote address |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
1 |
|
public function getRemoteAddress() |
71
|
|
|
{ |
72
|
1 |
|
return $this->remoteAddress; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|