mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 19:41:55 +02:00
38 lines
999 B
PHP
38 lines
999 B
PHP
<?php
|
|
|
|
namespace React\Socket;
|
|
|
|
use React\Stream\Stream;
|
|
|
|
class Connection extends Stream implements ConnectionInterface
|
|
{
|
|
public function handleData($stream)
|
|
{
|
|
// Socket is raw, not using fread as it's interceptable by filters
|
|
// See issues #192, #209, and #240
|
|
$data = stream_socket_recvfrom($stream, $this->bufferSize);
|
|
if ('' === $data || false === $data || feof($stream)) {
|
|
$this->end();
|
|
} else {
|
|
$this->emit('data', array($data, $this));
|
|
}
|
|
}
|
|
|
|
public function handleClose()
|
|
{
|
|
if (is_resource($this->stream)) {
|
|
stream_socket_shutdown($this->stream, STREAM_SHUT_RDWR);
|
|
fclose($this->stream);
|
|
}
|
|
}
|
|
|
|
public function getRemoteAddress()
|
|
{
|
|
return $this->parseAddress(stream_socket_get_name($this->stream, true));
|
|
}
|
|
|
|
private function parseAddress($address)
|
|
{
|
|
return trim(substr($address, 0, strrpos($address, ':')), '[]');
|
|
}
|
|
}
|