summaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/network/bind_in_range.cpp
blob: 3229ffad53024e42f891fc11011655587e4f229e (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
#include "bind_in_range.h"

#include <yql/essentials/utils/log/log.h>
#include <util/datetime/base.h>

namespace NYql {

TVector<NBus::TBindResult> BindInRange(TRangeWalker<int>& portWalker) {
    const int cyclesLimit = 3;
    const int rangeSize = portWalker.GetRangeSize();
    const auto cycleDelay = TDuration::Seconds(3);

    for (int cycle = 0; cycle < cyclesLimit; ++cycle) {
        for (int i = 0; i < rangeSize; ++i) {
            try {
                return NBus::BindOnPort(portWalker.MoveToNext(), false).second;
            } catch (const TSystemError&) {
                YQL_LOG(DEBUG) << CurrentExceptionMessage();
            }
        }

        Sleep(cycleDelay);
    }

    ythrow yexception() << "Unable to bind within port range [" << portWalker.GetStart() << ", " << portWalker.GetFinish() << "]";
}
} // namespace NYql