ConnectionInterface.php 1.6 KB

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