RPCResult.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: liyunlong
  5. * Date: 2018-12-24
  6. * Time: 11:54
  7. */
  8. namespace common\libs\swoole;
  9. class RPCResult
  10. {
  11. public $code = self::ERR_NO_READY;
  12. public $msg;
  13. public $data = null;
  14. public $send; //要发送的数据
  15. public $type;
  16. public $index;
  17. /**
  18. * 请求串号
  19. */
  20. public $requestId;
  21. /**
  22. * 回调函数
  23. * @var mixed
  24. */
  25. public $callback;
  26. /**
  27. * @var
  28. */
  29. public $socket = null;
  30. /**
  31. * SOA服务器的IP地址
  32. * @var string
  33. */
  34. public $server_host;
  35. /**
  36. * SOA服务器的端口
  37. * @var int
  38. */
  39. public $server_port;
  40. /**
  41. * @var RPCResult
  42. */
  43. protected $soa_client;
  44. const ERR_NO_READY = 8001; //未就绪
  45. const ERR_CONNECT = 8002; //连接服务器失败
  46. const ERR_TIMEOUT = 8003; //服务器端超时
  47. const ERR_SEND = 8004; //发送失败
  48. const ERR_SERVER = 8005; //server返回了错误码
  49. const ERR_UNPACK = 8006; //解包失败了
  50. const ERR_HEADER = 8007; //错误的协议头
  51. const ERR_TOOBIG = 8008; //超过最大允许的长度
  52. const ERR_CLOSED = 8009; //连接被关闭
  53. const ERR_RECV = 8010; //等待接收数据
  54. function __construct($soa_client)
  55. {
  56. $this->soa_client = $soa_client;
  57. }
  58. function getResult($timeout = 0.5)
  59. {
  60. if ($this->code == self::ERR_RECV)
  61. {
  62. $this->soa_client->wait($timeout);
  63. }
  64. return $this->data;
  65. }
  66. }