<?php /** @noinspection PhpIllegalPsrClassPathInspection */

namespace Kicken\Chat;


abstract class StreamSocketServer extends StreamSocket {
    /** @var callable[] */
    private array $mOnAccept = [];

    public function __construct($resource){
        parent::__construct($resource);
    }

    public function nowReadable() : void{
        $child = $this->accept();
        foreach ($this->mOnAccept as $cb){
            $cb($child);
        }
    }

    public function nowWritable() : void{
    }

    public function onAccept(callable $cb) : void{
        $this->mOnAccept[] = $cb;
    }

    public function hasPendingWrites() : bool{
        return false;
    }

    private function accept(){
        return stream_socket_accept($this->mResource);
    }
}