client_sync.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef __CLIENT_SYNC_H__
  17. #define __CLIENT_SYNC_H__
  18. #include "poll/poller.h"
  19. #include "timer/timer_list.h"
  20. #include "receiver.h"
  21. class DTCDecoderUnit;
  22. class DTCJobOperation;
  23. class Packet;
  24. class ClientResourceSlot;
  25. class ClientSync : public EpollBase, private TimerObject {
  26. public:
  27. DTCDecoderUnit *owner;
  28. void *addr;
  29. int addrLen;
  30. unsigned int resource_id;
  31. ClientResourceSlot *resource;
  32. uint32_t resource_seq;
  33. enum RscStatus {
  34. RscClean,
  35. RscDirty,
  36. };
  37. RscStatus rscStatus;
  38. ClientSync(DTCDecoderUnit *, int fd, void *, int);
  39. virtual ~ClientSync();
  40. virtual int do_attach(void);
  41. int send_result(void);
  42. virtual void input_notify(void);
  43. private:
  44. virtual void output_notify(void);
  45. int get_resource();
  46. void free_resource();
  47. void clean_resource();
  48. protected:
  49. enum ClientState {
  50. IdleState,
  51. RecvReqState, //wait for recv request, server side
  52. SendRepState, //wait for send response, server side
  53. ProcReqState, // IN processing
  54. };
  55. SimpleReceiver receiver;
  56. ClientState stage;
  57. DTCJobOperation *job;
  58. Packet *reply;
  59. int recv_request(void);
  60. int Response(void);
  61. void adjust_events(void);
  62. };
  63. #endif