udp_client_server.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include <util/generic/ptr.h>
  3. #include <util/generic/guid.h>
  4. #include <library/cpp/netliba/socket/socket.h>
  5. #include "udp_address.h"
  6. #include "net_request.h"
  7. namespace NNetliba {
  8. class TRopeDataPacket;
  9. struct TRequesterPendingDataStats;
  10. struct IPeerQueueStats;
  11. struct TSendResult {
  12. int TransferId;
  13. bool Success;
  14. TSendResult()
  15. : TransferId(-1)
  16. , Success(false)
  17. {
  18. }
  19. TSendResult(int transferId, bool success)
  20. : TransferId(transferId)
  21. , Success(success)
  22. {
  23. }
  24. };
  25. enum EPacketPriority {
  26. PP_LOW,
  27. PP_NORMAL,
  28. PP_HIGH
  29. };
  30. // Step should be called from one and the same thread
  31. // thread safety is caller responsibility
  32. struct IUdpHost: public TThrRefBase {
  33. virtual TRequest* GetRequest() = 0;
  34. // returns trasferId
  35. // Send() needs correctly computed crc32
  36. // crc32 is expected to be computed outside of the thread talking to IUdpHost to avoid crc32 computation delays
  37. // packetGuid provides packet guid, if packetGuid is empty then guid is generated
  38. virtual int Send(const TUdpAddress& addr, TAutoPtr<TRopeDataPacket> data, int crc32, TGUID* packetGuid, EPacketPriority pp) = 0;
  39. virtual bool GetSendResult(TSendResult* res) = 0;
  40. virtual void Step() = 0;
  41. virtual void IBStep() = 0;
  42. virtual void Wait(float seconds) = 0; // does not use UdpHost
  43. virtual void CancelWait() = 0; // thread safe
  44. virtual void GetPendingDataSize(TRequesterPendingDataStats* res) = 0;
  45. virtual TString GetDebugInfo() = 0;
  46. virtual void Kill(const TUdpAddress& addr) = 0;
  47. virtual TIntrusivePtr<IPeerQueueStats> GetQueueStats(const TUdpAddress& addr) = 0;
  48. };
  49. TIntrusivePtr<IUdpHost> CreateUdpHost(int port);
  50. TIntrusivePtr<IUdpHost> CreateUdpHost(const TIntrusivePtr<NNetlibaSocket::ISocket>& socket);
  51. void SetUdpMaxBandwidthPerIP(float f);
  52. void SetUdpSlowStart(bool enable);
  53. void DisableIBDetection();
  54. }