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