Skip to content

Commit

Permalink
update timer and add unix server abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
JanHuang committed Oct 13, 2017
1 parent 77d1d97 commit 49db592
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/timer/timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DemoTimer extends \FastD\Swoole\Timer
* @param array $params
* @return mixed
*/
public function doTick($id, array $params = [])
public function handle($id, array $params = [])
{
echo ++$this->count;
if (3 === $this->count) {
Expand Down
3 changes: 2 additions & 1 deletion examples/websocket/websocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public function doOpen(swoole_websocket_server $server, swoole_http_request $req
*/
public function doMessage(swoole_server $server, swoole_websocket_frame $frame)
{
echo $this->getFileDescriptor() . PHP_EOL;
echo $frame->fd;
echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
$server->push($frame->fd, "this is server");
}
}

Expand Down
20 changes: 11 additions & 9 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace FastD\Swoole;

use Exception;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Output\ConsoleOutput as Output;
use FastD\Swoole\Support\Watcher;
Expand All @@ -27,7 +26,7 @@
*/
abstract class Server
{
const VERSION = '2.0.0 (dev)';
const VERSION = '2.0.0';

/**
* @var $name
Expand Down Expand Up @@ -101,12 +100,7 @@ abstract class Server
/**
* @var int
*/
public $from_fd;

/**
* @var int
*/
public $to_fd;
protected $fd;

/**
* Server constructor.
Expand Down Expand Up @@ -201,6 +195,14 @@ public function getPort()
return $this->port;
}

/**
* @return int
*/
public function getFileDescriptor()
{
return $this->fd;
}

/**
* @return string
*/
Expand Down Expand Up @@ -664,7 +666,7 @@ abstract public function doFinish(swoole_server $server, $data, $taskId);
*/
public function onConnect(swoole_server $server, $fd, $from_id)
{
$this->from_fd = $fd;
$this->fd = $fd;

$this->doConnect($server, $fd, $from_id);
}
Expand Down
18 changes: 18 additions & 0 deletions src/Server/Unix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* @author jan huang <[email protected]>
* @copyright 2017
*
* @see https://www.github.com/janhuang
* @see http://www.fast-d.cn/
*/

namespace FastD\Swoole\Server;


use FastD\Swoole\Server;

abstract class Unix extends Server
{

}
6 changes: 3 additions & 3 deletions src/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function withServer(Server $server)
*/
public function tick()
{
$this->id = timer_tick($this->ms, [$this, 'doTick'], $this->params);
$this->id = timer_tick($this->ms, [$this, 'handle'], $this->params);

return $this->id;
}
Expand All @@ -82,7 +82,7 @@ public function tick()
*/
public function after()
{
$this->id = timer_after($this->ms, [$this, 'doTick'], $this->params);
$this->id = timer_after($this->ms, [$this, 'handle'], $this->params);

return $this->id;
}
Expand All @@ -100,5 +100,5 @@ public function clear()
* @param array $params
* @return mixed
*/
abstract public function doTick($id, array $params = []);
abstract public function handle($id, array $params = []);
}

0 comments on commit 49db592

Please sign in to comment.