aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/http/client/scheduler.cpp
blob: 87670bfb458e9e7664bb7f35f50b3dcfb4a22ddf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "scheduler.h"

namespace NHttp {
    namespace {
        class TDefaultHostsPolicy: public IHostsPolicy {
        public:
            size_t GetMaxHostConnections(const TStringBuf&) const override {
                return 20;
            }
        };

    }

    TScheduler::TScheduler()
        : HostsPolicy_(new TDefaultHostsPolicy)
    {
    }

    TFetchRequestRef TScheduler::Extract() {
        {
            auto g(Guard(Lock_));

            if (!RequestQueue_.empty()) {
                TFetchRequestRef result(RequestQueue_.front());
                RequestQueue_.pop();
                return result;
            }
        }
        return TFetchRequestRef();
    }

    void TScheduler::Schedule(TFetchRequestRef req) {
        auto g(Guard(Lock_));
        RequestQueue_.push(req);
    }

}