'.chr(10); } public static function ev_accept($socket, $flag, $base) { //echo __FILE__.'-'.__LINE__.''.chr(10); static $id = 0; $connection = stream_socket_accept($socket); stream_set_blocking($connection, 0); list($remoteIP, $remotePort) = explode(':',stream_socket_get_name($connection,true)); $id ++; $buffer = event_buffer_new($connection, 'epoll::ev_read', NULL, 'epoll::ev_error', $id); event_buffer_base_set($buffer, $base); event_buffer_timeout_set($buffer, 30, 30); event_buffer_watermark_set($buffer, EV_READ, 0, 0xffffff); event_buffer_priority_set($buffer, 60);//超时自动断开时间 event_buffer_enable($buffer, EV_READ | EV_PERSIST); // we need to save both buffer and connection outside self::$connections[$id] = $connection; self::$buffers[$id] = $buffer; //self::$link_msg->send(CONNECT_IN_MSG.$remoteIP.','.$remotePort, $id); self::$fd2pid[$id] = 0; //echo 'In-> $id='.$id.',$connection='.$connection."\n"; } public static function ev_error($buffer, $error, $id) { event_buffer_disable(self::$buffers[$id], EV_READ | EV_WRITE); event_buffer_free(self::$buffers[$id]); //echo 'Ot-> $id='.$id."\n"; //self::$link_msg->send(CONNECT_OUT_MSG, $id); fclose(self::$connections[$id]); unset(self::$fd2pid[$id]); unset(self::$buffers[$id], self::$connections[$id]); } public static function ev_read($buffer, $id) { //echo __FILE__.'-'.__LINE__.''.chr(10); static $ct=0; while ($read = event_buffer_read($buffer, 256)) { $ct+=strlen($read); if(strpos($read,'ct')!==false) echo 'Ct=>'.count(self::$connections).'\n'; $mid = self::$fd2pid[$id]; //self::$msgs[$mid]->send($read , $id); } } }