netliba_udp_http.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include <library/cpp/netliba/v6/net_queue_stat.h>
  3. #include <library/cpp/netliba/v6/udp_address.h>
  4. #include <library/cpp/netliba/v6/udp_debug.h>
  5. #include <util/generic/guid.h>
  6. #include <util/generic/ptr.h>
  7. #include <util/network/init.h>
  8. #include <util/system/event.h>
  9. namespace NNetliba {
  10. struct TRequest;
  11. }
  12. namespace NNehNetliba {
  13. using namespace NNetliba;
  14. typedef TAutoPtr<TRequest> TRequestPtr;
  15. class TUdpHttpMessage {
  16. public:
  17. TUdpHttpMessage(const TGUID& reqId, const TUdpAddress& peerAddr);
  18. TGUID ReqId;
  19. TUdpAddress PeerAddress;
  20. };
  21. class TUdpHttpRequest: public TUdpHttpMessage {
  22. public:
  23. TUdpHttpRequest(TRequestPtr& dataHolder, const TGUID& reqId, const TUdpAddress& peerAddr);
  24. TString Url;
  25. TVector<char> Data;
  26. };
  27. class TUdpHttpResponse: public TUdpHttpMessage {
  28. public:
  29. enum EResult {
  30. FAILED = 0,
  31. OK = 1,
  32. CANCELED = 2
  33. };
  34. TUdpHttpResponse(TRequestPtr& dataHolder, const TGUID& reqId, const TUdpAddress& peerAddr, EResult result, const char* error);
  35. EResult Ok;
  36. TString Data;
  37. TString Error;
  38. };
  39. class IRequester: public TThrRefBase {
  40. public:
  41. virtual void EnableReportRequestCancel() = 0;
  42. virtual void EnableReportRequestAck() = 0;
  43. // vector<char> *data - vector will be cleared upon call
  44. virtual void SendRequest(const TUdpAddress&, const TString& url, const TString& data, const TGUID&) = 0;
  45. virtual void CancelRequest(const TGUID&) = 0;
  46. virtual void SendResponse(const TGUID&, TVector<char>* data) = 0;
  47. virtual void StopNoWait() = 0;
  48. };
  49. class IEventsCollector: public TThrRefBase {
  50. public:
  51. // move ownership request/response object to event collector
  52. virtual void AddRequest(TUdpHttpRequest*) = 0;
  53. virtual void AddResponse(TUdpHttpResponse*) = 0;
  54. virtual void AddCancel(const TGUID&) = 0;
  55. virtual void AddRequestAck(const TGUID&) = 0;
  56. };
  57. typedef TIntrusivePtr<IEventsCollector> IEventsCollectorRef;
  58. typedef TIntrusivePtr<IRequester> IRequesterRef;
  59. // throw exception, if can't bind port
  60. IRequesterRef CreateHttpUdpRequester(int port, const IEventsCollectorRef&, int physicalCpu = -1);
  61. }