SocketWorker.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. <?php
  2. namespace Man\Core;
  3. require_once WORKERMAN_ROOT_DIR . 'man/Core/Events/Select.php';
  4. require_once WORKERMAN_ROOT_DIR . 'man/Core/AbstractWorker.php';
  5. require_once WORKERMAN_ROOT_DIR . 'man/Core/Lib/Config.php';
  6. /**
  7. * SocketWorker 监听某个端口,对外提供网络服务的worker
  8. *
  9. * @author walkor <worker-man@qq.com>
  10. *
  11. * <b>使用示例:</b>
  12. * <pre>
  13. * <code>
  14. * $worker = new SocketWorker();
  15. * $worker->start();
  16. * <code>
  17. * </pre>
  18. */
  19. abstract class SocketWorker extends AbstractWorker
  20. {
  21. /**
  22. * udp最大包长 linux:65507 mac:9216
  23. * @var integer
  24. */
  25. const MAX_UDP_PACKEG_SIZE = 65507;
  26. /**
  27. * 停止服务后等待EXIT_WAIT_TIME秒后还没退出则强制退出
  28. * @var integer
  29. */
  30. const EXIT_WAIT_TIME = 3;
  31. /**
  32. * worker的传输层协议
  33. * @var string
  34. */
  35. protected $protocol = "tcp";
  36. /**
  37. * worker监听端口的Socket
  38. * @var resource
  39. */
  40. protected $mainSocket = null;
  41. /**
  42. * worker接受的所有链接
  43. * @var array
  44. */
  45. protected $connections = array();
  46. /**
  47. * worker的所有读buffer
  48. * @var array
  49. */
  50. protected $recvBuffers = array();
  51. /**
  52. * 当前处理的fd
  53. * @var integer
  54. */
  55. protected $currentDealFd = 0;
  56. /**
  57. * UDP当前处理的客户端地址
  58. * @var string
  59. */
  60. protected $currentClientAddress = '';
  61. /**
  62. * 是否是长链接,(短连接每次请求后服务器主动断开,长连接一般是客户端主动断开)
  63. * @var bool
  64. */
  65. protected $isPersistentConnection = false;
  66. /**
  67. * 事件轮询库的名称
  68. * @var string
  69. */
  70. protected $eventLoopName ="\\Man\\Core\\Events\\Select";
  71. /**
  72. * 时间轮询库实例
  73. * @var object
  74. */
  75. protected $event = null;
  76. /**
  77. * 该worker进程处理多少请求后退出,0表示不自动退出
  78. * @var integer
  79. */
  80. protected $maxRequests = 0;
  81. /**
  82. * 预读长度
  83. * @var integer
  84. */
  85. protected $prereadLength = 4;
  86. /**
  87. * 该进程使用的php文件
  88. * @var array
  89. */
  90. protected $includeFiles = array();
  91. /**
  92. * 统计信息
  93. * @var array
  94. */
  95. protected $statusInfo = array(
  96. 'start_time' => 0, // 该进程开始时间戳
  97. 'total_request' => 0, // 该进程处理的总请求数
  98. 'recv_timeout' => 0, // 该进程接收数据超时总数
  99. 'proc_timeout' => 0, // 该进程逻辑处理超时总数
  100. 'packet_err' => 0, // 该进程收到错误数据包的总数
  101. 'throw_exception' => 0, // 该进程逻辑处理时收到异常的总数
  102. 'thunder_herd' => 0, // 该进程受惊群效应影响的总数
  103. 'client_close' => 0, // 客户端提前关闭链接总数
  104. 'send_fail' => 0, // 发送数据给客户端失败总数
  105. );
  106. /**
  107. * 用户worker继承此worker类必须实现该方法,根据具体协议和当前收到的数据决定是否继续收包
  108. * @param string $recv_str 收到的数据包
  109. * @return int/false 返回0表示接收完毕/>0表示还有多少字节没有接收到/false出错
  110. */
  111. abstract public function dealInput($recv_str);
  112. /**
  113. * 用户worker继承此worker类必须实现该方法,根据包中的数据处理逻辑
  114. * 逻辑处理
  115. * @param string $recv_str 收到的数据包
  116. * @return void
  117. */
  118. abstract public function dealProcess($recv_str);
  119. /**
  120. * 构造函数
  121. * @param int $port
  122. * @param string $ip
  123. * @param string $protocol
  124. * @return void
  125. */
  126. public function __construct()
  127. {
  128. // worker name
  129. $this->workerName = get_class($this);
  130. // 是否开启长连接
  131. $this->isPersistentConnection = (bool)Lib\Config::get( $this->workerName . '.persistent_connection');
  132. // 最大请求数,如果没有配置则使用PHP_INT_MAX
  133. $this->maxRequests = (int)Lib\Config::get( $this->workerName . '.max_requests');
  134. $this->maxRequests = $this->maxRequests <= 0 ? PHP_INT_MAX : $this->maxRequests;
  135. $preread_length = (int)Lib\Config::get( $this->workerName . '.preread_length');
  136. if($preread_length > 0)
  137. {
  138. $this->prereadLength = $preread_length;
  139. }
  140. elseif(!$this->isPersistentConnection)
  141. {
  142. $this->prereadLength = 65535;
  143. }
  144. // worker启动时间
  145. $this->statusInfo['start_time'] = time();
  146. //事件轮询库
  147. if(extension_loaded('libevent'))
  148. {
  149. $this->setEventLoopName('Libevent');
  150. }
  151. // 检查退出状态
  152. $this->addShutdownHook();
  153. // 初始化事件轮询库
  154. // $this->event = new Libevent();
  155. // $this->event = new Select();
  156. $this->event = new $this->eventLoopName();
  157. }
  158. /**
  159. * 让该worker实例开始服务
  160. *
  161. * @return void
  162. */
  163. public function start()
  164. {
  165. // 安装信号处理函数
  166. $this->installSignal();
  167. // 触发该worker进程onStart事件,该进程整个生命周期只触发一次
  168. if($this->onStart())
  169. {
  170. return;
  171. }
  172. if($this->protocol == 'udp')
  173. {
  174. // 添加读udp事件
  175. $this->event->add($this->mainSocket, Events\BaseEvent::EV_READ, array($this, 'recvUdp'));
  176. }
  177. else
  178. {
  179. // 添加accept事件
  180. $ret = $this->event->add($this->mainSocket, Events\BaseEvent::EV_READ, array($this, 'accept'));
  181. }
  182. // 主体循环,整个子进程会阻塞在这个函数上
  183. $ret = $this->event->loop();
  184. $this->notice('worker loop exit');
  185. exit(0);
  186. }
  187. /**
  188. * 停止服务
  189. * @param bool $exit 是否退出
  190. * @return void
  191. */
  192. public function stop($exit = true)
  193. {
  194. // 触发该worker进程onStop事件
  195. if($this->onStop())
  196. {
  197. return;
  198. }
  199. // 标记这个worker开始停止服务
  200. if($this->workerStatus != self::STATUS_SHUTDOWN)
  201. {
  202. // 停止接收连接
  203. $this->event->del($this->mainSocket, Events\BaseEvent::EV_READ);
  204. fclose($this->mainSocket);
  205. $this->workerStatus = self::STATUS_SHUTDOWN;
  206. }
  207. // 没有链接要处理了
  208. if($this->allTaskHasDone())
  209. {
  210. if($exit)
  211. {
  212. exit(0);
  213. }
  214. }
  215. }
  216. /**
  217. * 设置worker监听的socket
  218. * @param resource $socket
  219. * @return void
  220. */
  221. public function setListendSocket($socket)
  222. {
  223. // 初始化
  224. $this->mainSocket = $socket;
  225. // 设置监听socket非阻塞
  226. stream_set_blocking($this->mainSocket, 0);
  227. // 获取协议
  228. $mata_data = stream_get_meta_data($socket);
  229. $this->protocol = substr($mata_data['stream_type'], 0, 3);
  230. }
  231. /**
  232. * 设置worker的事件轮询库的名称
  233. * @param string
  234. * @return void
  235. */
  236. public function setEventLoopName($event_loop_name)
  237. {
  238. $this->eventLoopName = "\\Man\\Core\\Events\\".$event_loop_name;
  239. require_once WORKERMAN_ROOT_DIR . 'man/Core/Events/'.ucfirst(str_replace('WORKERMAN', '', $event_loop_name)).'.php';
  240. }
  241. /**
  242. * 接受一个链接
  243. * @param resource $socket
  244. * @param $null_one $flag
  245. * @param $null_two $base
  246. * @return void
  247. */
  248. public function accept($socket, $null_one = null, $null_two = null)
  249. {
  250. // 获得一个连接
  251. $new_connection = @stream_socket_accept($socket, 0);
  252. // 可能是惊群效应
  253. if(false === $new_connection)
  254. {
  255. $this->statusInfo['thunder_herd']++;
  256. return false;
  257. }
  258. // 接受请求数加1
  259. $this->statusInfo['total_request'] ++;
  260. // 连接的fd序号
  261. $fd = (int) $new_connection;
  262. $this->connections[$fd] = $new_connection;
  263. $this->recvBuffers[$fd] = array('buf'=>'', 'remain_len'=>$this->prereadLength);
  264. // 非阻塞
  265. stream_set_blocking($this->connections[$fd], 0);
  266. $this->event->add($this->connections[$fd], Events\BaseEvent::EV_READ , array($this, 'dealInputBase'), $fd);
  267. return $new_connection;
  268. }
  269. /**
  270. * 接收Udp数据
  271. * 如果数据超过一个udp包长,需要业务自己解析包体,判断数据是否全部到达
  272. * @param resource $socket
  273. * @param $null_one $flag
  274. * @param $null_two $base
  275. * @return void
  276. */
  277. public function recvUdp($socket, $null_one = null, $null_two = null)
  278. {
  279. $data = stream_socket_recvfrom($socket , self::MAX_UDP_PACKEG_SIZE, 0, $address);
  280. // 可能是惊群效应
  281. if(false === $data || empty($address))
  282. {
  283. $this->statusInfo['thunder_herd']++;
  284. return false;
  285. }
  286. // 接受请求数加1
  287. $this->statusInfo['total_request'] ++;
  288. $this->currentClientAddress = $address;
  289. if(0 === $this->dealInput($data))
  290. {
  291. $this->dealProcess($data);
  292. }
  293. }
  294. /**
  295. * 处理受到的数据
  296. * @param event_buffer $event_buffer
  297. * @param int $fd
  298. * @return void
  299. */
  300. public function dealInputBase($connection, $flag, $fd = null)
  301. {
  302. $this->currentDealFd = $fd;
  303. $buffer = stream_socket_recvfrom($connection, $this->recvBuffers[$fd]['remain_len']);
  304. // 出错了
  305. if('' == $buffer)
  306. {
  307. if(feof($connection))
  308. {
  309. // 客户端提前断开链接
  310. $this->statusInfo['client_close']++;
  311. // 如果该链接对应的buffer有数据,说明放生错误
  312. if(!empty($this->recvBuffers[$fd]['buf']))
  313. {
  314. $this->notice("CLIENT_CLOSE\nCLIENT_IP:".$this->getRemoteIp()."\nBUFFER:[".var_export($this->recvBuffers[$fd]['buf'],true)."]\n");
  315. }
  316. }
  317. else
  318. {
  319. // 超时了
  320. $this->statusInfo['recv_timeout']++;
  321. // 如果该链接对应的buffer有数据,说明放生错误
  322. if(!empty($this->recvBuffers[$fd]['buf']))
  323. {
  324. $this->notice("RECV_TIMEOUT\nCLIENT_IP:".$this->getRemoteIp()."\nBUFFER:[".var_export($this->recvBuffers[$fd]['buf'],true)."]\n");
  325. }
  326. }
  327. // 关闭链接
  328. $this->closeClient($fd);
  329. if($this->workerStatus == self::STATUS_SHUTDOWN)
  330. {
  331. $this->stop();
  332. }
  333. return;
  334. }
  335. $this->recvBuffers[$fd]['buf'] .= $buffer;
  336. $remain_len = $this->dealInput($this->recvBuffers[$fd]['buf']);
  337. // 包接收完毕
  338. if(0 === $remain_len)
  339. {
  340. // 执行处理
  341. try{
  342. // 业务处理
  343. $this->dealProcess($this->recvBuffers[$fd]['buf']);
  344. }
  345. catch(\Exception $e)
  346. {
  347. $this->notice('CODE:' . $e->getCode() . ' MESSAGE:' . $e->getMessage()."\n".$e->getTraceAsString()."\nCLIENT_IP:".$this->getRemoteIp()."\nBUFFER:[".var_export($this->recvBuffers[$fd]['buf'],true)."]\n");
  348. $this->statusInfo['throw_exception'] ++;
  349. $this->sendToClient($e->getMessage());
  350. }
  351. // 是否是长连接
  352. if($this->isPersistentConnection)
  353. {
  354. // 清空缓冲buffer
  355. $this->recvBuffers[$fd] = array('buf'=>'', 'remain_len'=>$this->prereadLength);
  356. }
  357. else
  358. {
  359. // 关闭链接
  360. $this->closeClient($fd);
  361. }
  362. }
  363. // 出错
  364. else if(false === $remain_len)
  365. {
  366. // 出错
  367. $this->statusInfo['packet_err']++;
  368. $this->sendToClient('packet_err:'.$this->recvBuffers[$fd]['buf']);
  369. $this->notice("PACKET_ERROR\nCLIENT_IP:".$this->getRemoteIp()."\nBUFFER:[".var_export($this->recvBuffers[$fd]['buf'],true)."]\n");
  370. $this->closeClient($fd);
  371. }
  372. else
  373. {
  374. $this->recvBuffers[$fd]['remain_len'] = $remain_len;
  375. }
  376. // 检查是否是关闭状态或者是否到达请求上限
  377. if($this->workerStatus == self::STATUS_SHUTDOWN || $this->statusInfo['total_request'] >= $this->maxRequests)
  378. {
  379. // 关闭链接
  380. if($this->isPersistentConnection)
  381. {
  382. $this->closeClient($fd);
  383. }
  384. // 停止服务
  385. $this->stop();
  386. // EXIT_WAIT_TIME秒后退出进程
  387. pcntl_alarm(self::EXIT_WAIT_TIME);
  388. }
  389. }
  390. /**
  391. * 根据fd关闭链接
  392. * @param int $fd
  393. * @return void
  394. */
  395. protected function closeClient($fd)
  396. {
  397. // udp忽略
  398. if($this->protocol != 'udp')
  399. {
  400. $this->event->del($this->connections[$fd], Events\BaseEvent::EV_READ);
  401. fclose($this->connections[$fd]);
  402. unset($this->connections[$fd], $this->recvBuffers[$fd]);
  403. }
  404. }
  405. /**
  406. * 安装信号处理函数
  407. * @return void
  408. */
  409. protected function installSignal()
  410. {
  411. // 闹钟信号
  412. $this->event->add(SIGALRM, Events\BaseEvent::EV_SIGNAL, array($this, 'signalHandler'), SIGALRM);
  413. // 终止进程信号
  414. $this->event->add(SIGINT, Events\BaseEvent::EV_SIGNAL, array($this, 'signalHandler'), SIGINT);
  415. // 平滑重启信号
  416. $this->event->add(SIGHUP, Events\BaseEvent::EV_SIGNAL, array($this, 'signalHandler'), SIGHUP);
  417. // 报告进程状态
  418. $this->event->add(SIGUSR1, Events\BaseEvent::EV_SIGNAL, array($this, 'signalHandler'), SIGUSR1);
  419. // 报告该进程使用的文件
  420. $this->event->add(SIGUSR2, Events\BaseEvent::EV_SIGNAL, array($this, 'signalHandler'), SIGUSR2);
  421. // 设置忽略信号
  422. pcntl_signal(SIGTTIN, SIG_IGN);
  423. pcntl_signal(SIGTTOU, SIG_IGN);
  424. pcntl_signal(SIGQUIT, SIG_IGN);
  425. pcntl_signal(SIGPIPE, SIG_IGN);
  426. pcntl_signal(SIGCHLD, SIG_IGN);
  427. }
  428. /**
  429. * 设置server信号处理函数
  430. * @param null $null
  431. * @param int $signal
  432. */
  433. public function signalHandler($signal, $null = null, $null = null)
  434. {
  435. switch($signal)
  436. {
  437. // 时钟处理函数
  438. case SIGALRM:
  439. // 停止服务后EXIT_WAIT_TIME秒还没退出则强制退出
  440. if($this->workerStatus == self::STATUS_SHUTDOWN)
  441. {
  442. exit(0);
  443. }
  444. break;
  445. // 停止该进程
  446. case SIGINT:
  447. // 平滑重启
  448. case SIGHUP:
  449. $this->stop();
  450. // EXIT_WAIT_TIME秒后退出进程
  451. pcntl_alarm(self::EXIT_WAIT_TIME);
  452. break;
  453. // 报告进程状态
  454. case SIGUSR1:
  455. $this->writeStatusToQueue();
  456. break;
  457. // 报告进程使用的php文件
  458. case SIGUSR2:
  459. $this->writeFilesListToQueue();
  460. break;
  461. }
  462. }
  463. /**
  464. * 发送数据到客户端
  465. * @return bool
  466. */
  467. public function sendToClient($str_to_send)
  468. {
  469. // tcp
  470. if($this->protocol != 'udp')
  471. {
  472. // tcp 如果一次没写完(一般是缓冲区满的情况),则阻塞写
  473. if(!$this->blockWrite($this->connections[$this->currentDealFd], $str_to_send, 500))
  474. {
  475. $this->notice('sendToClient fail ,Data length = ' . strlen($str_to_send));
  476. $this->statusInfo['send_fail']++;
  477. return false;
  478. }
  479. return true;
  480. }
  481. // udp 直接发送,要求数据包不能超过65515
  482. return strlen($str_to_send) == stream_socket_sendto($this->mainSocket, $str_to_send, 0, $this->currentClientAddress);
  483. }
  484. /**
  485. * 向fd写数据,如果socket缓冲区满了,则改用阻塞模式写数据
  486. * @param resource $fd
  487. * @param string $str_to_write
  488. * @param int $time_out 单位毫秒
  489. * @return bool
  490. */
  491. protected function blockWrite($fd, $str_to_write, $timeout_ms = 500)
  492. {
  493. $send_len = @fwrite($fd, $str_to_write);
  494. if($send_len == strlen($str_to_write))
  495. {
  496. return true;
  497. }
  498. // 客户端关闭
  499. if(feof($fd))
  500. {
  501. $this->notice("blockWrite client close");
  502. return false;
  503. }
  504. // 设置阻塞
  505. stream_set_blocking($fd, 1);
  506. // 设置超时
  507. $timeout_sec = floor($timeout_ms/1000);
  508. $timeout_ms = $timeout_ms%1000;
  509. stream_set_timeout($fd, $timeout_sec, $timeout_ms*1000);
  510. $send_len += @fwrite($fd, substr($str_to_write, $send_len));
  511. // 改回非阻塞
  512. stream_set_blocking($fd, 0);
  513. return $send_len == strlen($str_to_write);
  514. }
  515. /**
  516. * 获取客户端ip
  517. * @param int $fd 已经链接的socket id
  518. * @return string
  519. */
  520. public function getRemoteIp($fd = null)
  521. {
  522. if(empty($fd))
  523. {
  524. if(!isset($this->connections[$this->currentDealFd]))
  525. {
  526. return '0.0.0.0';
  527. }
  528. $fd = $this->currentDealFd;
  529. }
  530. $ip = '';
  531. if($this->protocol == 'udp')
  532. {
  533. $sock_name = $this->currentClientAddress;
  534. }
  535. else
  536. {
  537. $sock_name = stream_socket_get_name($this->connections[$fd], true);
  538. }
  539. if($sock_name)
  540. {
  541. $tmp = explode(':', $sock_name);
  542. $ip = $tmp[0];
  543. }
  544. return $ip;
  545. }
  546. /**
  547. * 获取本地ip
  548. * @return string
  549. */
  550. public function getLocalIp()
  551. {
  552. $ip = '';
  553. $sock_name = '';
  554. if($this->protocol == 'udp' || !isset($this->connections[$this->currentDealFd]))
  555. {
  556. $sock_name = stream_socket_get_name($this->mainSocket, false);
  557. }
  558. else
  559. {
  560. $sock_name = stream_socket_get_name($this->connections[$this->currentDealFd], false);
  561. }
  562. if($sock_name)
  563. {
  564. $tmp = explode(':', $sock_name);
  565. $ip = $tmp[0];
  566. }
  567. if(empty($ip) || '127.0.0.1' == $ip)
  568. {
  569. $ip = gethostbyname(trim(`hostname`));
  570. }
  571. return $ip;
  572. }
  573. /**
  574. * 将当前worker进程状态写入消息队列
  575. * @return void
  576. */
  577. protected function writeStatusToQueue()
  578. {
  579. if(!Master::getQueueId())
  580. {
  581. return;
  582. }
  583. $error_code = 0;
  584. msg_send(Master::getQueueId(), self::MSG_TYPE_STATUS, array_merge($this->statusInfo, array('memory'=>memory_get_usage(true), 'pid'=>posix_getpid(), 'worker_name' => $this->workerName)), true, false, $error_code);
  585. }
  586. /**
  587. * 开发环境将当前进程使用的文件写入消息队列,用于FileMonitor监控文件更新
  588. * @return void
  589. */
  590. protected function writeFilesListToQueue()
  591. {
  592. if(!Master::getQueueId())
  593. {
  594. return;
  595. }
  596. $error_code = 0;
  597. $flip_file_list = array_flip(get_included_files());
  598. $file_list = array_diff_key($flip_file_list, $this->includeFiles);
  599. $this->includeFiles = $flip_file_list;
  600. if($file_list)
  601. {
  602. msg_send(Master::getQueueId(), self::MSG_TYPE_FILE_MONITOR, array_keys($file_list), true, false, $error_code);
  603. }
  604. }
  605. /**
  606. * 是否所有任务都已经完成
  607. * @return bool
  608. */
  609. protected function allTaskHasDone()
  610. {
  611. // 如果是长链接并且没有要处理的数据则是任务都处理完了
  612. return $this->noConnections() || ($this->isPersistentConnection && $this->allBufferIsEmpty());
  613. }
  614. /**
  615. * 检查是否所有的链接的缓冲区都是空
  616. * @return bool
  617. */
  618. protected function allBufferIsEmpty()
  619. {
  620. foreach($this->recvBuffers as $fd => $buf)
  621. {
  622. if(!empty($buf['buf']))
  623. {
  624. return false;
  625. }
  626. }
  627. return true;
  628. }
  629. /**
  630. * 该进程收到的任务是否都已经完成,重启进程时需要判断
  631. * @return bool
  632. */
  633. protected function noConnections()
  634. {
  635. return empty($this->connections);
  636. }
  637. /**
  638. * 该worker进程开始服务的时候会触发一次,可以在这里做一些全局的事情
  639. * @return bool
  640. */
  641. protected function onStart()
  642. {
  643. return false;
  644. }
  645. /**
  646. * 该worker进程停止服务的时候会触发一次,可以在这里做一些全局的事情
  647. * @return bool
  648. */
  649. protected function onStop()
  650. {
  651. return false;
  652. }
  653. }