Skip to content

Commit 49db592

Browse files
committed
update timer and add unix server abstract
1 parent 77d1d97 commit 49db592

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

examples/timer/timer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DemoTimer extends \FastD\Swoole\Timer
1818
* @param array $params
1919
* @return mixed
2020
*/
21-
public function doTick($id, array $params = [])
21+
public function handle($id, array $params = [])
2222
{
2323
echo ++$this->count;
2424
if (3 === $this->count) {

examples/websocket/websocket.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public function doOpen(swoole_websocket_server $server, swoole_http_request $req
2828
*/
2929
public function doMessage(swoole_server $server, swoole_websocket_frame $frame)
3030
{
31+
echo $this->getFileDescriptor() . PHP_EOL;
32+
echo $frame->fd;
3133
echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
32-
$server->push($frame->fd, "this is server");
3334
}
3435
}
3536

src/Server.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace FastD\Swoole;
1111

1212
use Exception;
13-
use Psr\Http\Message\ResponseInterface;
1413
use Symfony\Component\Console\Helper\Table;
1514
use Symfony\Component\Console\Output\ConsoleOutput as Output;
1615
use FastD\Swoole\Support\Watcher;
@@ -27,7 +26,7 @@
2726
*/
2827
abstract class Server
2928
{
30-
const VERSION = '2.0.0 (dev)';
29+
const VERSION = '2.0.0';
3130

3231
/**
3332
* @var $name
@@ -101,12 +100,7 @@ abstract class Server
101100
/**
102101
* @var int
103102
*/
104-
public $from_fd;
105-
106-
/**
107-
* @var int
108-
*/
109-
public $to_fd;
103+
protected $fd;
110104

111105
/**
112106
* Server constructor.
@@ -201,6 +195,14 @@ public function getPort()
201195
return $this->port;
202196
}
203197

198+
/**
199+
* @return int
200+
*/
201+
public function getFileDescriptor()
202+
{
203+
return $this->fd;
204+
}
205+
204206
/**
205207
* @return string
206208
*/
@@ -664,7 +666,7 @@ abstract public function doFinish(swoole_server $server, $data, $taskId);
664666
*/
665667
public function onConnect(swoole_server $server, $fd, $from_id)
666668
{
667-
$this->from_fd = $fd;
669+
$this->fd = $fd;
668670

669671
$this->doConnect($server, $fd, $from_id);
670672
}

src/Server/Unix.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* @author jan huang <bboyjanhuang@gmail.com>
4+
* @copyright 2017
5+
*
6+
* @see https://www.github.com/janhuang
7+
* @see http://www.fast-d.cn/
8+
*/
9+
10+
namespace FastD\Swoole\Server;
11+
12+
13+
use FastD\Swoole\Server;
14+
15+
abstract class Unix extends Server
16+
{
17+
18+
}

src/Timer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function withServer(Server $server)
7272
*/
7373
public function tick()
7474
{
75-
$this->id = timer_tick($this->ms, [$this, 'doTick'], $this->params);
75+
$this->id = timer_tick($this->ms, [$this, 'handle'], $this->params);
7676

7777
return $this->id;
7878
}
@@ -82,7 +82,7 @@ public function tick()
8282
*/
8383
public function after()
8484
{
85-
$this->id = timer_after($this->ms, [$this, 'doTick'], $this->params);
85+
$this->id = timer_after($this->ms, [$this, 'handle'], $this->params);
8686

8787
return $this->id;
8888
}
@@ -100,5 +100,5 @@ public function clear()
100100
* @param array $params
101101
* @return mixed
102102
*/
103-
abstract public function doTick($id, array $params = []);
103+
abstract public function handle($id, array $params = []);
104104
}

0 commit comments

Comments
 (0)