multi.cpp 970 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "rpc.h"
  2. #include "multi.h"
  3. #include "location.h"
  4. #include "factory.h"
  5. #include <util/string/cast.h>
  6. #include <util/generic/hash.h>
  7. using namespace NNeh;
  8. namespace {
  9. namespace NMulti {
  10. class TRequester: public IRequester {
  11. public:
  12. inline TRequester(const TListenAddrs& addrs, IOnRequest* cb) {
  13. for (const auto& addr : addrs) {
  14. TParsedLocation loc(addr);
  15. IRequesterRef& req = R_[ToString(loc.Scheme) + ToString(loc.GetPort())];
  16. if (!req) {
  17. req = ProtocolFactory()->Protocol(loc.Scheme)->CreateRequester(cb, loc);
  18. }
  19. }
  20. }
  21. private:
  22. typedef THashMap<TString, IRequesterRef> TRequesters;
  23. TRequesters R_;
  24. };
  25. }
  26. }
  27. IRequesterRef NNeh::MultiRequester(const TListenAddrs& addrs, IOnRequest* cb) {
  28. return new NMulti::TRequester(addrs, cb);
  29. }