utils.h 986 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include <library/cpp/threading/atomic/bool.h>
  3. #include <util/network/address.h>
  4. #include <util/system/thread.h>
  5. #include <util/generic/cast.h>
  6. #include <library/cpp/deprecated/atomic/atomic.h>
  7. namespace NNeh {
  8. typedef TAutoPtr<TThread> TThreadRef;
  9. template <typename T, void (T::*M)()>
  10. static void* HelperMemberFunc(void* arg) {
  11. T* obj = reinterpret_cast<T*>(arg);
  12. (obj->*M)();
  13. return nullptr;
  14. }
  15. template <typename T, void (T::*M)()>
  16. static TThreadRef Spawn(T* t) {
  17. TThreadRef thr(new TThread(HelperMemberFunc<T, M>, t));
  18. thr->Start();
  19. return thr;
  20. }
  21. size_t RealStackSize(size_t len) noexcept;
  22. //from rfc3986:
  23. //host = IP-literal / IPv4address / reg-name
  24. //IP-literal = "[" ( IPv6address / IPvFuture ) "]"
  25. TString PrintHostByRfc(const NAddr::IRemoteAddr& addr);
  26. NAddr::IRemoteAddrPtr GetPeerAddr(SOCKET s);
  27. using TAtomicBool = NAtomic::TBool;
  28. }