-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventServer.class.php
More file actions
executable file
·51 lines (47 loc) · 1.25 KB
/
EventServer.class.php
File metadata and controls
executable file
·51 lines (47 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php namespace peer\server;
/**
* Basic TCP/IP Server using libevent
*
* @ext event
* @see http://pecl.php.net/package/event
* @deprecated In favor of AsynchronousServer
*/
class EventServer extends Server {
/**
* Service
*
* @return void
*/
public function service() {
if (!$this->socket->isConnected()) return false;
$base= new \EventBase();
$listener= new \EventListener(
$base,
function($listener, $fd, $address, $base) {
$event= new \EventBufferEvent($base, $fd, \EventBufferEvent::OPT_CLOSE_ON_FREE);
$event->setCallbacks(
function($event) {
foreach ($this->protocol->handleData(new EventSocket($event)) ?? [] as $_) { }
},
function($event) {
if (0 === $event->output->length) {
$event->free();
}
},
function($event, $events) {
if ($events & (\EventBufferEvent::EOF | \EventBufferEvent::ERROR)) {
$event->free();
}
},
null
);
$event->enable(\Event::READ);
},
$base,
\EventListener::OPT_CLOSE_ON_FREE | \EventListener::OPT_REUSEABLE,
-1,
$this->socket->getHandle()
);
$base->dispatch();
}
}