ConnectionInterface.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * This file is part of workerman.
  4. *
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the MIT-LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @author walkor<walkor@workerman.net>
  10. * @copyright walkor<walkor@workerman.net>
  11. * @link http://www.workerman.net/
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Workerman\Connection;
  15. use Workerman\Events\Libevent;
  16. use Workerman\Events\Select;
  17. use Workerman\Events\EventInterface;
  18. use Workerman\Worker;
  19. use \Exception;
  20. /**
  21. * connection类的接口
  22. */
  23. abstract class ConnectionInterface
  24. {
  25. /**
  26. * status命令的统计数据
  27. * @var array
  28. */
  29. public static $statistics = array(
  30. 'connection_count'=>0,
  31. 'total_request' => 0,
  32. 'throw_exception' => 0,
  33. 'send_fail' => 0,
  34. );
  35. /**
  36. * 当收到数据时,如果有设置$onMessage回调,则执行
  37. * @var callback
  38. */
  39. public $onMessage = null;
  40. /**
  41. * 当连接关闭时,如果设置了$onClose回调,则执行
  42. * @var callback
  43. */
  44. public $onClose = null;
  45. /**
  46. * 当出现错误时,如果设置了$onError回调,则执行
  47. * @var callback
  48. */
  49. public $onError = null;
  50. /**
  51. * 发送数据给对端
  52. * @param string $send_buffer
  53. * @return void|boolean
  54. */
  55. abstract public function send($send_buffer);
  56. /**
  57. * 获得远端ip
  58. * @return string
  59. */
  60. abstract public function getRemoteIp();
  61. /**
  62. * 获得远端端口
  63. * @return int
  64. */
  65. abstract public function getRemotePort();
  66. /**
  67. * 关闭连接,为了保持接口一致,udp保留了此方法,当是udp时调用此方法无任何作用
  68. * @void
  69. */
  70. abstract public function close($data = null);
  71. }