@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @param resource $resource PHP socket resource, or `null` for the global error. |
28 | 28 | * @return int If the resource is closed or not a socket, `SOCKET_EBADF` is returned. |
29 | 29 | */ |
30 | - public static function getLast ($resource = null) { |
|
30 | + public static function getLast($resource = null) { |
|
31 | 31 | if (isset($resource)) { |
32 | 32 | if (@get_resource_type($resource) !== 'Socket') { |
33 | 33 | return SOCKET_EBADF; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * PHP's last suppressed warning is used for the message. |
54 | 54 | * |
55 | 55 | */ |
56 | - public function __construct ($subject = null, $fallback = 0) { |
|
56 | + public function __construct($subject = null, $fallback = 0) { |
|
57 | 57 | if (is_int($subject)) { |
58 | 58 | $errno = $subject; |
59 | 59 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | /** |
74 | 74 | * @return mixed |
75 | 75 | */ |
76 | - public function getExtra () { |
|
76 | + public function getExtra() { |
|
77 | 77 | return $this->extra; |
78 | 78 | } |
79 | 79 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @param mixed $extra |
82 | 82 | * @return $this |
83 | 83 | */ |
84 | - public function setExtra ($extra) { |
|
84 | + public function setExtra($extra) { |
|
85 | 85 | $this->extra = $extra; |
86 | 86 | return $this; |
87 | 87 | } |
@@ -14,13 +14,13 @@ |
||
14 | 14 | * |
15 | 15 | * @return void |
16 | 16 | */ |
17 | - public function onExceptional (); |
|
17 | + public function onExceptional(); |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Called by the reactor when the socket has readable data. |
21 | 21 | * |
22 | 22 | * @return void |
23 | 23 | */ |
24 | - public function onReadable (); |
|
24 | + public function onReadable(); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | \ No newline at end of file |
@@ -42,34 +42,34 @@ |
||
42 | 42 | * |
43 | 43 | * @return int `AF_*` |
44 | 44 | */ |
45 | - public function getDomain (); |
|
45 | + public function getDomain(); |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Returns the underlying socket resource as an integer. |
49 | 49 | * |
50 | 50 | * @return int |
51 | 51 | */ |
52 | - public function getId (); |
|
52 | + public function getId(); |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Returns the protocol constant used by the socket. |
56 | 56 | * |
57 | 57 | * @return int |
58 | 58 | */ |
59 | - public function getProtocol (); |
|
59 | + public function getProtocol(); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Returns the underlying socket resource. |
63 | 63 | * |
64 | 64 | * @return resource |
65 | 65 | */ |
66 | - public function getResource (); |
|
66 | + public function getResource(); |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * Returns the socket type constant for the class. |
70 | 70 | * |
71 | 71 | * @return int `SOCK_*` |
72 | 72 | */ |
73 | - public static function getType (); |
|
73 | + public static function getType(); |
|
74 | 74 | |
75 | 75 | } |
76 | 76 | \ No newline at end of file |
@@ -17,8 +17,7 @@ |
||
17 | 17 | public function __toString () { |
18 | 18 | try { |
19 | 19 | return implode(':', $this->getSockName()); |
20 | - } |
|
21 | - catch (\Exception $exception) { |
|
20 | + } catch (\Exception $exception) { |
|
22 | 21 | return ':'; |
23 | 22 | } |
24 | 23 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @return string |
16 | 16 | */ |
17 | - public function __toString () { |
|
17 | + public function __toString() { |
|
18 | 18 | try { |
19 | 19 | return implode(':', $this->getPeerName()); |
20 | 20 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @throws Error |
39 | 39 | * @return $this |
40 | 40 | */ |
41 | - public function connect ($address, $port = 0) { |
|
41 | + public function connect($address, $port = 0) { |
|
42 | 42 | if (!@socket_connect($this->resource, $address, $port)) { |
43 | 43 | // ignore expected errors for non-blocking connections |
44 | 44 | $errno = Error::getLast($this->resource); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @throws Error |
59 | 59 | * @return array Address and port at indices `0` and `1`. |
60 | 60 | */ |
61 | - public function getPeerName () { |
|
61 | + public function getPeerName() { |
|
62 | 62 | if ($this->domain === AF_UNIX) { |
63 | 63 | return [$this->getOption(self::SO_PEERCRED), 0]; |
64 | 64 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @throws Error |
81 | 81 | * @return int Total bytes sent. |
82 | 82 | */ |
83 | - public function send ($data, $flags = 0) { |
|
83 | + public function send($data, $flags = 0) { |
|
84 | 84 | $count = @socket_send($this->resource, $data, PHP_INT_MAX, $flags); |
85 | 85 | if ($count === false) { |
86 | 86 | $error = new Error($this->resource); // reliable errno |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @throws Error Total bytes sent is set as the error's extra data. |
100 | 100 | * @return $this |
101 | 101 | */ |
102 | - public function write ($data) { |
|
102 | + public function write($data) { |
|
103 | 103 | $data = (string)$data; |
104 | 104 | $length = strlen($data); |
105 | 105 | $total = 0; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @return static |
42 | 42 | * @throws Error |
43 | 43 | */ |
44 | - public static function create ($domain = AF_INET, ...$extra) { |
|
44 | + public static function create($domain = AF_INET, ...$extra) { |
|
45 | 45 | if (!$resource = @socket_create($domain, static::getType(), 0)) { // auto-protocol |
46 | 46 | throw new Error; // reliable errno |
47 | 47 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return int |
61 | 61 | * @throws Error |
62 | 62 | */ |
63 | - public static function select (array &$read, array &$write, array &$except, $timeout = null) { |
|
63 | + public static function select(array &$read, array &$write, array &$except, $timeout = null) { |
|
64 | 64 | $getResource = function(SocketInterface $socket) { |
65 | 65 | return $socket->getResource(); |
66 | 66 | }; |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | * @throws Error (`SOCKET_EBADFD`) There was a pending error on the socket. |
91 | 91 | * The preexisting error code is set as the exception's extra data. |
92 | 92 | */ |
93 | - public function __construct ($resource) { |
|
93 | + public function __construct($resource) { |
|
94 | 94 | if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') { |
95 | 95 | throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF); |
96 | 96 | } |
97 | 97 | elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
98 | - throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT); |
|
98 | + throw new InvalidArgumentException('The given socket resource is of the wrong type for '.get_class(), SOCKET_ESOCKTNOSUPPORT); |
|
99 | 99 | } |
100 | 100 | elseif ($errno = Error::getLast($resource)) { |
101 | 101 | $error = new Error(SOCKET_EBADFD); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | /** |
111 | 111 | * Closes the socket if it's open. |
112 | 112 | */ |
113 | - public function __destruct () { |
|
113 | + public function __destruct() { |
|
114 | 114 | $this->close(); |
115 | 115 | } |
116 | 116 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @return $this |
126 | 126 | * @throws Error |
127 | 127 | */ |
128 | - public function await ($channel) { |
|
128 | + public function await($channel) { |
|
129 | 129 | $select = [$channel => [$this->resource]]; |
130 | 130 | $count = @socket_select($select[self::CH_READ], $select[self::CH_WRITE], $select[self::CH_EXCEPT], null); |
131 | 131 | if (!$count) { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @return $this |
146 | 146 | */ |
147 | - public function close () { |
|
147 | + public function close() { |
|
148 | 148 | // socket_close() never errors, but we guard anyway to prevent |
149 | 149 | // a redundant call to onClose(), and an incorrect call to it if |
150 | 150 | // the constructor failed and the destructor is calling this. |
@@ -158,14 +158,14 @@ discard block |
||
158 | 158 | /** |
159 | 159 | * @return int |
160 | 160 | */ |
161 | - final public function getDomain () { |
|
161 | + final public function getDomain() { |
|
162 | 162 | return $this->domain; |
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | 166 | * @return int |
167 | 167 | */ |
168 | - final public function getId () { |
|
168 | + final public function getId() { |
|
169 | 169 | return (int)$this->resource; |
170 | 170 | } |
171 | 171 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @throws Error |
179 | 179 | * @return mixed The option's value. This is never `false`. |
180 | 180 | */ |
181 | - public function getOption ($option) { |
|
181 | + public function getOption($option) { |
|
182 | 182 | $value = @socket_get_option($this->resource, SOL_SOCKET, $option); |
183 | 183 | if ($value === false) { |
184 | 184 | throw new Error($this->resource, SOCKET_EINVAL); |
@@ -189,14 +189,14 @@ discard block |
||
189 | 189 | /** |
190 | 190 | * @return int |
191 | 191 | */ |
192 | - final public function getProtocol () { |
|
192 | + final public function getProtocol() { |
|
193 | 193 | return $this->protocol; |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @return resource |
198 | 198 | */ |
199 | - final public function getResource () { |
|
199 | + final public function getResource() { |
|
200 | 200 | return $this->resource; |
201 | 201 | } |
202 | 202 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @throws Error |
209 | 209 | * @return array String address/file and integer port at indices `0` and `1`. |
210 | 210 | */ |
211 | - public function getSockName () { |
|
211 | + public function getSockName() { |
|
212 | 212 | if (!@socket_getsockname($this->resource, $addr, $port)) { |
213 | 213 | throw new Error($this->resource, SOCKET_EOPNOTSUPP); |
214 | 214 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * @return bool |
224 | 224 | * @throws Error |
225 | 225 | */ |
226 | - public function isExceptional () { |
|
226 | + public function isExceptional() { |
|
227 | 227 | return $this->isReady(self::CH_EXCEPT); |
228 | 228 | } |
229 | 229 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * |
233 | 233 | * @return bool |
234 | 234 | */ |
235 | - public function isOpen () { |
|
235 | + public function isOpen() { |
|
236 | 236 | return is_resource($this->resource); |
237 | 237 | } |
238 | 238 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @return bool |
245 | 245 | * @throws Error |
246 | 246 | */ |
247 | - public function isReadable () { |
|
247 | + public function isReadable() { |
|
248 | 248 | return $this->isReady(self::CH_READ); |
249 | 249 | } |
250 | 250 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @throws Error |
259 | 259 | * @return bool |
260 | 260 | */ |
261 | - public function isReady ($channel, $timeout = 0.0) { |
|
261 | + public function isReady($channel, $timeout = 0.0) { |
|
262 | 262 | $usec = (int)(fmod($timeout, 1) * 1000000); // ignored if timeout is null |
263 | 263 | $select = [$channel => [$this->resource]]; |
264 | 264 | $count = $count = @socket_select($select[self::CH_READ], $select[self::CH_WRITE], $select[self::CH_EXCEPT], $timeout, $usec); |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @return bool |
277 | 277 | * @throws Error |
278 | 278 | */ |
279 | - public function isWritable () { |
|
279 | + public function isWritable() { |
|
280 | 280 | return $this->isReady(self::CH_WRITE, 0); |
281 | 281 | } |
282 | 282 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return void |
287 | 287 | */ |
288 | - protected function onClose () { } |
|
288 | + protected function onClose() { } |
|
289 | 289 | |
290 | 290 | /** |
291 | 291 | * Stub. Called before an I/O channel is shut down. |
@@ -293,14 +293,14 @@ discard block |
||
293 | 293 | * @param int $channel `SocketInterface` channel constant. |
294 | 294 | * @return void |
295 | 295 | */ |
296 | - protected function onShutdown ($channel) { } |
|
296 | + protected function onShutdown($channel) { } |
|
297 | 297 | |
298 | 298 | /** |
299 | 299 | * Stub. Called when an I/O timeout has occurred, before it's thrown. |
300 | 300 | * |
301 | 301 | * @return void |
302 | 302 | */ |
303 | - protected function onTimeout () { } |
|
303 | + protected function onTimeout() { } |
|
304 | 304 | |
305 | 305 | /** |
306 | 306 | * Enables or disables blocking. |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | * @throws Error |
321 | 321 | * @return $this |
322 | 322 | */ |
323 | - public function setBlocking ($blocking) { |
|
323 | + public function setBlocking($blocking) { |
|
324 | 324 | if ($blocking) { |
325 | 325 | $success = @socket_set_block($this->resource); |
326 | 326 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | * @throws Error |
344 | 344 | * @return $this |
345 | 345 | */ |
346 | - public function setOption ($option, $value) { |
|
346 | + public function setOption($option, $value) { |
|
347 | 347 | if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) { |
348 | 348 | throw new Error($this->resource, SOCKET_EINVAL); |
349 | 349 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * @throws Error |
358 | 358 | * @return $this |
359 | 359 | */ |
360 | - public function setTimeout ($timeout) { |
|
360 | + public function setTimeout($timeout) { |
|
361 | 361 | $timeval = ['sec' => (int)$timeout, 'usec' => (int)(fmod($timeout, 1) * 1000000)]; |
362 | 362 | $this->setOption(SO_RCVTIMEO, $timeval); |
363 | 363 | $this->setOption(SO_SNDTIMEO, $timeval); |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | * @throws Error |
385 | 385 | * @return $this |
386 | 386 | */ |
387 | - public function shutdown ($channel) { |
|
387 | + public function shutdown($channel) { |
|
388 | 388 | $this->onShutdown($channel); |
389 | 389 | if (!@socket_shutdown($this->resource, $channel)) { |
390 | 390 | throw new Error($this->resource); // reliable errno |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @return int |
14 | 14 | */ |
15 | - final public static function getType () { |
|
15 | + final public static function getType() { |
|
16 | 16 | return SOCK_DGRAM; |
17 | 17 | } |
18 | 18 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @throws Error |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - public function recv ($length, $flags = 0, &$name = null, &$port = 0) { |
|
33 | + public function recv($length, $flags = 0, &$name = null, &$port = 0) { |
|
34 | 34 | $count = @socket_recvfrom($this->resource, $data, $length, $flags, $name, $port); |
35 | 35 | if ($count === false) { |
36 | 36 | $error = new Error($this->resource, SOCKET_EOPNOTSUPP); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @return int |
14 | 14 | */ |
15 | - final public static function getType () { |
|
15 | + final public static function getType() { |
|
16 | 16 | return SOCK_STREAM; |
17 | 17 | } |
18 | 18 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @throws Error |
28 | 28 | * @return StreamClient The accepted connection, as a client instance. |
29 | 29 | */ |
30 | - public function accept () { |
|
30 | + public function accept() { |
|
31 | 31 | if (!$resource = @socket_accept($this->resource)) { |
32 | 32 | throw new Error($this->resource); // reliable errno |
33 | 33 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @return StreamClient |
44 | 44 | * @throws Error |
45 | 45 | */ |
46 | - protected function createClient ($resource) { |
|
46 | + protected function createClient($resource) { |
|
47 | 47 | return new StreamClient($resource); |
48 | 48 | } |
49 | 49 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @throws Error |
58 | 58 | * @return $this |
59 | 59 | */ |
60 | - public function listen ($backlog = 0) { |
|
60 | + public function listen($backlog = 0) { |
|
61 | 61 | if (!@socket_listen($this->resource, $backlog)) { |
62 | 62 | throw new Error($this->resource); // reliable errno |
63 | 63 | } |
@@ -70,6 +70,6 @@ discard block |
||
70 | 70 | * @param StreamClient $client |
71 | 71 | * @return void |
72 | 72 | */ |
73 | - protected function onAccept (StreamClient $client) { } |
|
73 | + protected function onAccept(StreamClient $client) { } |
|
74 | 74 | |
75 | 75 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @return static[] Two instances at indices `0` and `1`. |
18 | 18 | * @throws Error |
19 | 19 | */ |
20 | - public static function createUnixPair (...$extra) { |
|
20 | + public static function createUnixPair(...$extra) { |
|
21 | 21 | if (!@socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $fd)) { |
22 | 22 | throw new Error; // reliable errno |
23 | 23 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return int |
34 | 34 | */ |
35 | - final public static function getType () { |
|
35 | + final public static function getType() { |
|
36 | 36 | return SOCK_STREAM; |
37 | 37 | } |
38 | 38 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return string |
47 | 47 | * @throws Error The error's extra data is set to what was partially read. |
48 | 48 | */ |
49 | - public function read ($length) { |
|
49 | + public function read($length) { |
|
50 | 50 | $data = ''; |
51 | 51 | while ($length > 0) { |
52 | 52 | try { |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @throws Error |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - public function recv ($length, $flags = 0) { |
|
79 | + public function recv($length, $flags = 0) { |
|
80 | 80 | $count = @socket_recv($this->resource, $data, $length, $flags); |
81 | 81 | if ($count === false) { |
82 | 82 | $error = new Error($this->resource, SOCKET_EINVAL); |