1 | <?php |
||
23 | class StreamSocketClient |
||
24 | { |
||
25 | /** |
||
26 | * @deprecated deprecated since v1.4.0 |
||
27 | */ |
||
28 | const SOCKET_TIMEOUT = 30; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $host; |
||
34 | |||
35 | /** |
||
36 | * @var integer |
||
37 | */ |
||
38 | protected $port; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $scheme; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $context; |
||
49 | |||
50 | /** |
||
51 | * @var resource |
||
52 | */ |
||
53 | protected $socket; |
||
54 | |||
55 | /** |
||
56 | * @var int |
||
57 | */ |
||
58 | protected $connectTimeout = self::SOCKET_TIMEOUT; |
||
59 | |||
60 | /** |
||
61 | * @param string $scheme |
||
62 | * @param string $host |
||
63 | * @param integer $port |
||
64 | * @param array $context |
||
65 | */ |
||
66 | 41 | public function __construct($scheme, $host, $port, array $context = array()) |
|
73 | |||
74 | /** |
||
75 | * Destructor, closes socket if possible |
||
76 | */ |
||
77 | 41 | public function __destruct() |
|
81 | |||
82 | /** |
||
83 | * Initializes socket-client |
||
84 | * |
||
85 | * @deprecated deprecated since v1.4.0 |
||
86 | * |
||
87 | * @param string $scheme like "udp" or "tcp" |
||
88 | * @param string $host |
||
89 | * @param integer $port |
||
90 | * @param array $context |
||
91 | * |
||
92 | * @return resource |
||
93 | * |
||
94 | * @throws RuntimeException on connection-failure |
||
95 | */ |
||
96 | protected static function initSocket($scheme, $host, $port, array $context) |
||
126 | |||
127 | |||
128 | /** |
||
129 | * Internal function mimicking the behaviour of static::initSocket |
||
130 | * which will get new functionality instead of the deprecated |
||
131 | * "factory" |
||
132 | * |
||
133 | * @return resource |
||
134 | * |
||
135 | * @throws RuntimeException on connection-failure |
||
136 | */ |
||
137 | 14 | private function buildSocket() |
|
173 | |||
174 | /** |
||
175 | * Returns raw-socket-resource |
||
176 | * |
||
177 | * @return resource |
||
178 | */ |
||
179 | 14 | public function getSocket() |
|
188 | |||
189 | /** |
||
190 | * Writes a given string to the socket and returns the |
||
191 | * number of written bytes |
||
192 | * |
||
193 | * @param string $buffer |
||
194 | * |
||
195 | * @return int |
||
196 | * |
||
197 | * @throws RuntimeException on write-failure |
||
198 | */ |
||
199 | 8 | public function write($buffer) |
|
234 | |||
235 | /** |
||
236 | * Reads a given number of bytes from the socket |
||
237 | * |
||
238 | * @param integer $byteCount |
||
239 | * |
||
240 | * @return string |
||
241 | */ |
||
242 | 2 | public function read($byteCount) |
|
246 | |||
247 | /** |
||
248 | * Closes underlying socket explicitly |
||
249 | */ |
||
250 | 41 | public function close() |
|
259 | |||
260 | /** |
||
261 | * Returns the current connect-timeout |
||
262 | * |
||
263 | * @return int |
||
264 | */ |
||
265 | 1 | public function getConnectTimeout() |
|
269 | |||
270 | /** |
||
271 | * Sets the connect-timeout |
||
272 | * |
||
273 | * @param int $timeout |
||
274 | */ |
||
275 | 1 | public function setConnectTimeout($timeout) |
|
279 | } |
||
280 |