<?php /** @noinspection PhpIllegalPsrClassPathInspection */

namespace Kicken\Chat;


abstract class StreamSocket implements ISelectable {
    /** @var resource  */
    protected $mResource = null;

    public function __construct($resource){
        $this->mResource = $resource;
        stream_set_blocking($resource, 0);
    }

    public function getResource(){
        return $this->mResource;
    }

    public function close() : void{
        if ($this->mResource){
            fclose($this->mResource);
            $this->mResource = null;
        }
    }

    public function isConnected() : bool{
        return $this->mResource !== null;
    }
}