Ev目次
Ev クラスはじめにEv は静的クラスで、デフォルトのループへのアクセスや各種共通操作へのアクセスを提供します。 クラス概要
Ev
final
class Ev
{
/* 定数 */
const
int
Ev::FLAG_AUTO = 0;
const
int
Ev::FLAG_NOENV = 16777216;
const
int
Ev::FLAG_FORKCHECK = 33554432;
const
int
Ev::FLAG_NOINOTIFY = 1048576;
const
int
Ev::FLAG_SIGNALFD = 2097152;
const
int
Ev::FLAG_NOSIGMASK = 4194304;
const
int
Ev::RUN_NOWAIT = 1;
const
int
Ev::RUN_ONCE = 2;
const
int
Ev::BREAK_CANCEL = 0;
const
int
Ev::BREAK_ONE = 1;
const
int
Ev::BREAK_ALL = 2;
const
int
Ev::MINPRI = -2;
const
int
Ev::MAXPRI = 2;
const
int
Ev::READ = 1;
const
int
Ev::WRITE = 2;
const
int
Ev::TIMER = 256;
const
int
Ev::PERIODIC = 512;
const
int
Ev::SIGNAL = 1024;
const
int
Ev::CHILD = 2048;
const
int
Ev::STAT = 4096;
const
int
Ev::IDLE = 8192;
const
int
Ev::PREPARE = 16384;
const
int
Ev::CHECK = 32768;
const
int
Ev::EMBED = 65536;
const
int
Ev::CUSTOM = 16777216;
const
int
Ev::ERROR = 2147483648;
const
int
Ev::BACKEND_SELECT = 1;
const
int
Ev::BACKEND_POLL = 2;
const
int
Ev::BACKEND_EPOLL = 4;
const
int
Ev::BACKEND_KQUEUE = 8;
const
int
Ev::BACKEND_DEVPOLL = 16;
const
int
Ev::BACKEND_PORT = 32;
const
int
Ev::BACKEND_ALL = 63;
const
int
Ev::BACKEND_MASK = 65535;
/* メソッド */
final
public
static
int backend()
final
public
static
int depth()
final
public
static
int embeddableBackends()
final
public
static
void feedSignal(
int
$signum
)final
public
static
void feedSignalEvent(
int
$signum
)final
public
static
int iteration()
final
public
static
float now()
final
public
static
void nowUpdate()
final
public
static
int recommendedBackends()
final
public
static
void resume()
final
public
static
void run(
int
$flags
= ?)final
public
static
void sleep(
float
$seconds
)final
public
static
void stop(
int
$how
= ?)final
public
static
int supportedBackends()
final
public
static
void suspend()
final
public
static
float time()
final
public
static
void verify()
}定義済み定数ループを作るときに渡すフラグ
Ev::run あるいは EvLoop::run に渡すフラグ
Ev::stop あるいは EvLoop::stop に渡すフラグ
ウォッチャーの優先度
受信したイベントのビットマスク
バックエンドのフラグ
EvCheck クラスはじめにEvPrepare ウォッチャーと EvCheck ウォッチャーは、 通常はペアで使います。 EvPrepare ウォッチャーはプロセスをブロックする前に起動し、 EvCheck はブロックした後に起動します。 EvLoop::run あるいはそれに類するメソッドや関数 (現在のイベントループに入るもの) は、EvPrepare ウォッチャーや EvCheck ウォッチャーからは呼べません。 現在のループ以外のループは問題ありません。 その理由は、これらのウォッチャーの中では再帰をチェックする必要がないからです。 つまり、処理の流れは常に EvPrepare -> ブロック -> EvCheck となるので、これらのウォッチャーは常にペアで呼ばれ、ブロッキング呼び出しの前後を囲むことになります。 主な利用目的は他のイベント機構を libev に統合することで、 少し高度な使いかたになります。変数の変更を追跡したり 自前のウォッチャーを実装したり、net-snmp やコルーチンライブラリを統合したりといった、 さまざまな用途で使えます。 また、何らかのデータをキャッシュしてブロッキングの前にフラッシュするなどの用途で使えることもあります。
EvCheck には最高の優先度
( また、EvCheck ウォッチャーはイベントをアクティブにしたり送信したりしてはいけません。 libev では対応してはいますが、 他の EvCheck ウォッチャーが仕事をする前に実行される可能性があります。 クラス概要
EvCheck
class EvCheck
extends
EvWatcher
{
/* 継承したプロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
public
__construct(
callable
$callback
,
mixed
$data
= ?,
int
$priority
= ?)final
public
static
object createStopped(
string
$callback
,
string
$data
= ?,
string
$priority
= ?)/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}The EvChild classはじめに
EvChild ウォッチャーは、子プロセスの状態の変更
(たいていは、停止したり終了したりといったもの)
に反応してこのプロセスが EvChild ウォッチャーは、 デフォルトループ の中でだけ登録できます。 クラス概要
EvChild
class EvChild
extends
EvWatcher
{
/* プロパティ */
public
$pid;
public
$rpid;
public
$rstatus;
/* 継承したプロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
public
__construct(
int $pid
,bool $trace
,callable $callback
,mixed $data
= null
,int $priority
= 0
) final
public
static
object createStopped(
int $pid
,bool $trace
,callable $callback
,mixed $data
= ?,int $priority
= ?) public
void set(
int
$pid
,
bool
$trace
)/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}プロパティ
EvEmbed クラスはじめにイベントループを別のイベントループに埋め込むために使います。 クラス概要
EvEmbed
class EvEmbed
extends
EvWatcher
{
/* プロパティ */
public
$embed;
/* メソッド */
public
__construct(
object $other
,callable $callback
= ?,mixed $data
= ?,int $priority
= ?) final
public
static
void createStopped(
object $other
,callable $callback
= ?,mixed $data
= ?,int $priority
= ?) public
void set(
object
$other
)public
void sweep()
/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}プロパティ
EvFork クラスはじめに
Fork ウォッチャーが呼ばれるのは、 クラス概要
EvFork
class EvFork
extends
EvWatcher
{
/* 継承したプロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
public
__construct(
callable
$callback
,
mixed
$data
= null
,
int
$priority
= 0
)final
public
static
object createStopped(
string
$callback
,
string
$data
= ?,
string
$priority
= ?)/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}The EvIdle classはじめにEvIdle watchers trigger events when no other events of the same or higher priority are pending ( EvPrepare , EvCheck and other EvIdle watchers do not count as receiving events ). Thus, as long as the process is busy handling sockets or timeouts(or even signals) of the same or higher priority it will not be triggered. But when the process is in idle(or only lower-priority watchers are pending), the EvIdle watchers are being called once per event loop iteration - until stopped, that is, or the process receives more events and becomes busy again with higher priority stuff. Apart from keeping the process non-blocking(which is a useful on its own sometimes), EvIdle watchers are a good place to do "pseudo-background processing" , or delay processing stuff to after the event loop has handled all outstanding events. The most noticeable effect is that as long as any idle watchers are active, the process will not block when waiting for new events. クラス概要
EvIdle
class EvIdle
extends
EvWatcher
{
/* 継承したプロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
public
__construct(
callable
$callback
,
mixed
$data
= ?,
int
$priority
= ?)final
public
static
object createStopped(
string
$callback
,
mixed
$data
= ?,
int
$priority
= ?)/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}The EvIo classはじめにEvIo watchers check whether a file descriptor(or socket, or a stream castable to numeric file descriptor) is readable or writable in each iteration of the event loop, or, more precisely, when reading would not block the process and writing would at least be able to write some data. This behaviour is called level-triggering because events are kept receiving as long as the condition persists. To stop receiving events just stop the watcher.
The number of read and/or write event watchers per
Another thing to watch out for is that it is quite easy to receive false
readiness notifications, i.e. the callback might be called with
If for some reason it is impossible to run the
Always consider using non-blocking mode. クラス概要
EvIo
class EvIo
extends
EvWatcher
{
/* プロパティ */
public
$fd;
public
$events;
/* 継承したプロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
public
__construct(
mixed $fd
,int $events
,callable $callback
,mixed $data
= ?,int $priority
= ?) final
public
static
EvIo createStopped(
mixed $fd
,int $events
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
void set(
mixed
$fd
,
int
$events
)/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}プロパティ
The EvLoop classはじめにRepresents an event loop that is always distinct from the default loop . Unlike the default loop , it cannot handle EvChild watchers. Having threads we have to create a loop per thread, and use the default loop in the parent thread. The default event loop is initialized automatically by Ev . It is accessible via methods of the Ev class, or via EvLoop::defaultLoop method. クラス概要
EvLoop
final
class EvLoop
{
/* プロパティ */
public
$data;
public
$backend;
public
$is_default_loop;
public
$iteration;
public
$pending;
public
$io_interval;
public
$timeout_interval;
public
$depth;
/* メソッド */
public
__construct(
int $flags
= ?,mixed $data
= NULL
,float $io_interval
= 0.0
,float $timeout_interval
= 0.0
) public
int backend()
final
public
EvCheck check(
string
$callback
,
string
$data
= ?,
string
$priority
= ?)final
public
EvChild child(
string $pid
,string $trace
,string $callback
,string $data
= ?,string $priority
= ?) public
static
EvLoop defaultLoop(
int $flags
= Ev::FLAG_AUTO
,mixed $data
= NULL
,float $io_interval
= 0.
,float $timeout_interval
= 0.
) final
public
EvEmbed embed(
string $other
,string $callback
= ?,string $data
= ?,string $priority
= ?) final
public
EvFork fork(
callable
$callback
,
mixed
$data
= null
,
int
$priority
= 0
)final
public
EvIdle idle(
callable
$callback
,
mixed
$data
= null
,
int
$priority
= 0
)public
void invokePending()
final
public
EvIo io(
mixed $fd
,int $events
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
void loopFork()
public
float now()
public
void nowUpdate()
final
public
EvPeriodic periodic(
float $offset
,float $interval
,callable $callback
,mixed $data
= null
,int $priority
= 0
) final
public
EvPrepare prepare(
callable
$callback
,
mixed
$data
= null
,
int
$priority
= 0
)public
void resume()
public
void run(
int
$flags
= 0
)final
public
EvSignal signal(
int $signum
,callable $callback
,mixed $data
= null
,int $priority
= 0
) final
public
EvStat stat(
string $path
,float $interval
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
void stop(
int
$how
= ?)public
void suspend()
final
public
EvTimer timer(
float $after
,float $repeat
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
void verify()
}プロパティ
The EvPeriodic classはじめにPeriodic watchers are also timers of a kind, but they are very versatile. Unlike EvTimer , EvPeriodic watchers are not based on real time(or relative time, the physical time that passes) but on wall clock time(absolute time, calendar or clock). The difference is that wall clock time can run faster or slower than real time, and time jumps are not uncommon(e.g. when adjusting it).
EvPeriodic
watcher can be configured to trigger after some specific point in time.
For example, if an
EvPeriodic
watcher is configured to trigger
"in 10 seconds"
(e.g.
EvLoop::now
+
As with timers, the callback is guaranteed to be invoked only when the point in time where it is supposed to trigger has passed. If multiple timers become ready during the same loop iteration then the ones with earlier time-out values are invoked before ones with later time-out values (but this is no longer true when a callback calls EvLoop::run recursively). クラス概要
EvPeriodic
class EvPeriodic
extends
EvWatcher
{
/* プロパティ */
public
$offset;
public
$interval;
/* 継承したプロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
public
__construct(
float $offset
,string $interval
,callable $reschedule_cb
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
void again()
public
float at()
final
public
static
EvPeriodic createStopped(
float $offset
,float $interval
,callable $reschedule_cb
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
void set(
float
$offset
,
float
$interval
)/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}プロパティ
EvPrepare クラスはじめにEvPrepare ウォッチャーと EvCheck ウォッチャーは、 通常はペアで使います。 EvPrepare ウォッチャーはプロセスをブロックする前に起動し、 EvCheck はブロックした後に起動します。 EvLoop::run あるいはそれに類するメソッドや関数 (現在のイベントループに入るもの) は、EvPrepare ウォッチャーや EvCheck ウォッチャーからは呼べません。 現在のループ以外のループは問題ありません。 その理由は、これらのウォッチャーの中では再帰をチェックする必要がないからです。 つまり、処理の流れは常に EvPrepare -> ブロック -> EvCheck となるので、これらのウォッチャーは常にペアで呼ばれ、ブロッキング呼び出しの前後を囲むことになります。 主な利用目的は他のイベント機構を libev に統合することで、 少し高度な使いかたになります。変数の変更を追跡したり 自前のウォッチャーを実装したり、net-snmp やコルーチンライブラリを統合したりといった、 さまざまな用途で使えます。 また、何らかのデータをキャッシュしてブロッキングの前にフラッシュするなどの用途で使えることもあります。
EvCheck には最高の優先度
( また、EvCheck ウォッチャーはイベントをアクティブにしたり送信したりしてはいけません。 libev では対応してはいますが、 他の EvCheck ウォッチャーが仕事をする前に実行される可能性があります。 クラス概要
EvPrepare
class EvPrepare
extends
EvWatcher
{
/* 継承したプロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
public
__construct(
string
$callback
,
string
$data
= ?,
string
$priority
= ?)final
public
static
EvPrepare createStopped(
callable
$callback
,
mixed
$data
= null
,
int
$priority
= 0
)/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}The EvSignal classはじめにEvSignal watchers will trigger an event when the process receives a specific signal one or more times. Even though signals are very asynchronous, libev will try its best to deliver signals synchronously, i.e. as part of the normal event processing, like any other event.
There is no limit for the number of watchers for the same signal, but only
within the same loop, i.e. one can watch for
If possible and supported,
libev
will install its handlers with
クラス概要
EvSignal
class EvSignal
extends
EvWatcher
{
/* プロパティ */
public
$signum;
/* 継承したプロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
public
__construct(
int $signum
,callable $callback
,mixed $data
= null
,int $priority
= 0
) final
public
static
EvSignal createStopped(
int $signum
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
void set(
int
$signum
)/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}プロパティ
The EvStat classはじめにEvStat monitors a file system path for attribute changes. It calls stat() on that path in regular intervals (or when the OS signals it changed) and sees if it changed compared to the last time, invoking the callback if it did.
The path does not need to exist: changing from "path exists" to "path does
not exist" is a status change like any other. The condition "path does not
exist" is signified by the
The path must not end in a slash or contain special components such as
Since there is no portable change notification interface available, the
portable implementation simply calls
stat()
regularly on the path to see if it changed somehow. For this case a
recommended polling interval can be specified. If one specifies a polling
interval of
This watcher type is not meant for massive numbers of EvStat watchers, as even with OS-supported change notifications, this can be resource-intensive. クラス概要
EvStat
class EvStat
extends
EvWatcher
{
/* プロパティ */
public
$path;
public
$interval;
/* 継承したプロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
public
__construct(
string $path
,float $interval
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
array attr()
final
public
static
void createStopped(
string $path
,float $interval
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
void prev()
public
void set(
string
$path
,
float
$interval
)public
bool stat()
/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}プロパティ
The EvTimer classはじめにEvTimer watchers are simple relative timers that generate an event after a given time, and optionally repeating in regular intervals after that. The timers are based on real time, that is, if one registers an event that times out after an hour and resets the system clock to January last year , it will still time out after(roughly) one hour. "Roughly" because detecting time jumps is hard, and some inaccuracies are unavoidable. The callback is guaranteed to be invoked only after its timeout has passed (not at, so on systems with very low-resolution clocks this might introduce a small delay). If multiple timers become ready during the same loop iteration then the ones with earlier time-out values are invoked before ones of the same priority with later time-out values (but this is no longer true when a callback calls EvLoop::run recursively).
The timer itself will do a best-effort at avoiding drift, that is, if a
timer is configured to trigger every
クラス概要
EvTimer
class EvTimer
extends
EvWatcher
{
/* プロパティ */
public
$repeat;
public
$remaining;
/* 継承したプロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
public
__construct(
float $after
,float $repeat
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
void again()
final
public
static
EvTimer createStopped(
float $after
,float $repeat
,callable $callback
,mixed $data
= null
,int $priority
= 0
) public
void set(
float
$after
,
float
$repeat
)/* 継承したメソッド */
public
int EvWatcher::clear()
public
void EvWatcher::feed(
int
$revents
)public
EvLoop EvWatcher::getLoop()
public
void EvWatcher::invoke(
int
$revents
)public
bool EvWatcher::keepalive(
bool
$value
= ?)public
void EvWatcher::setCallback(
callable
$callback
)public
void EvWatcher::start()
public
void EvWatcher::stop()
}プロパティ
The EvWatcher classはじめにEvWatcher is a base class for all watchers( EvCheck , EvChild etc.). Since EvWatcher 's constructor is abstract , one can't(and don't need to) create EvWatcher objects directly. クラス概要
EvWatcher
abstract
class EvWatcher
{
/* プロパティ */
public
$is_active;
public
$data;
public
$is_pending;
public
$priority;
/* メソッド */
abstract
public
__construct()
public
int clear()
public
void feed(
int
$revents
)public
EvLoop getLoop()
public
void invoke(
int
$revents
)public
bool keepalive(
bool
$value
= ?)public
void setCallback(
callable
$callback
)public
void start()
public
void stop()
}プロパティ
|