stanley-king 6 년 전
부모
커밋
e91a9afbf3
6개의 변경된 파일20개의 추가작업 그리고 18개의 파일을 삭제
  1. 1 9
      helper/room/factory_processor.php
  2. 4 0
      helper/room/room_processor.php
  3. 5 0
      helper/search/processor.php
  4. 5 3
      helper/search/srv_base.php
  5. 4 4
      helper/search/tcp_client.php
  6. 1 2
      test/TestRoomSrv.php

+ 1 - 9
helper/room/factory_processor.php

@@ -28,10 +28,9 @@ class factory_processor implements IProcessor
         $this->mLastBuilding = 0;
         $this->mAccUniquer = new uniquer();
         $this->mBufidRooms = [];
-        $this->init();
     }
 
-    private function init()
+    public function onStart()
     {
         global $config;
         $room_addrs = $config['room_factory']['rooms_addr'];
@@ -203,10 +202,6 @@ class factory_processor implements IProcessor
                 $ret = $client->invite($roomid,$inviter,$invitees);
                 $this->unblock($bufid);
 
-                if($ret != false) {
-                    //todo broad cast all access
-                }
-
                 return $ret;
             }
         }
@@ -237,9 +232,6 @@ class factory_processor implements IProcessor
                 $ret = $client->leave($roomid,$user);
                 $this->unblock($bufid);
 
-                if($ret != false) {
-                    //todo broad cast all access
-                }
                 return $ret;
             }
         }

+ 4 - 0
helper/room/room_processor.php

@@ -28,6 +28,10 @@ class room_processor implements IProcessor
         $this->mChatwo = new chatwo();
     }
 
+    public function onStart()
+    {
+
+    }
     public function onConnected($bufid,$stream,$host,$port,$args)
     {
 

+ 5 - 0
helper/search/processor.php

@@ -26,6 +26,11 @@ class processor implements IProcessor
 
     const ValidateArea   = 20;
 
+    public function onStart()
+    {
+
+    }
+
     public function onConnected($bufid,$stream,$host,$port,$args)
     {
 

+ 5 - 3
helper/search/srv_base.php

@@ -13,6 +13,7 @@ use Log;
 
 interface IProcessor
 {
+    public function onStart();
     public function onRequest($bufid, $body);
     public function onClose($bufid);
     public function onConnected($bufid,$stream,$host,$port,$args);
@@ -52,6 +53,7 @@ abstract class srv_base
     public function init(IProcessor $processor)
     {
         $this->mProcessor = $processor;
+        $this->mProcessor->onStart();
     }
 
     public function run_loop($sock)
@@ -65,13 +67,13 @@ abstract class srv_base
         Log::record("event_base_loop ret={$ret}",Log::DEBUG);
     }
 
-    private function add_listen($fd)
+    private function add_listen($stream)
     {
-        $fd = intval($fd);
+        $fd = intval($stream);
         if($fd < 0) return false;
 
         $this->mEvAccepts[$fd] = event_new();
-        if(event_set($this->mEvAccepts[$fd], $fd, EV_READ | EV_PERSIST, [$this, 'onAccept'], $this->mEvBase) == false) {
+        if(event_set($this->mEvAccepts[$fd], $stream, EV_READ | EV_PERSIST, [$this, 'onAccept'], $this->mEvBase) == false) {
             Log::record("event_set error EV_READ | EV_PERSIST",Log::DEBUG);
         }
 

+ 4 - 4
helper/search/tcp_client.php

@@ -9,6 +9,7 @@
 namespace search;
 
 use Log;
+use scope_trace;
 
 abstract class tcp_client
 {
@@ -111,10 +112,9 @@ abstract class tcp_client
     private function read_body()
     {
         do {
-
-            $body = $this->read(self::body_header_len);
-            if($body === false) return false;
-            $body_len = intval($body);
+            $header = $this->read(self::body_header_len);
+            if($header === false) return false;
+            $body_len = intval($header);
         }
         while($body_len === 0);
 

+ 1 - 2
test/TestRoomSrv.php

@@ -80,8 +80,7 @@ class TestRoomSrv extends PHPUnit_Framework_TestCase
     {
         $invitee = 36507;
         $processor = new room\room_processor();
-        $ret = $processor->onRequest(0,json_encode(["act" => 'factory','op' => 'push','seq' => 1,
-            'content' => 'hello world']));
+        $ret = $processor->onRequest(0,json_encode(["act" => 'factory','op' => 'push','seq' => 1,'content' => 'hello world']));
     }
 
     private function creator($room_id)