ConnectionInterface.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /**
  16. * ConnectionInterface.
  17. */
  18. abstract class ConnectionInterface
  19. {
  20. /**
  21. * Statistics for status command.
  22. *
  23. * @var array
  24. */
  25. public static $statistics = array(
  26. 'connection_count' => 0,
  27. 'total_request' => 0,
  28. 'throw_exception' => 0,
  29. 'send_fail' => 0,
  30. );
  31. /**
  32. * Emitted when data is received.
  33. *
  34. * @var callback
  35. */
  36. public $onMessage = null;
  37. /**
  38. * Emitted when the other end of the socket sends a FIN packet.
  39. *
  40. * @var callback
  41. */
  42. public $onClose = null;
  43. /**
  44. * Emitted when an error occurs with connection.
  45. *
  46. * @var callback
  47. */
  48. public $onError = null;
  49. /**
  50. * Sends data on the connection.
  51. *
  52. * @param string $send_buffer
  53. * @return void|boolean
  54. */
  55. abstract public function send($send_buffer);
  56. /**
  57. * Get remote IP.
  58. *
  59. * @return string
  60. */
  61. abstract public function getRemoteIp();
  62. /**
  63. * Get remote port.
  64. *
  65. * @return int
  66. */
  67. abstract public function getRemotePort();
  68. /**
  69. * Close connection.
  70. *
  71. * @param $data
  72. * @return void
  73. */
  74. abstract public function close($data = null);
  75. }