2021-05-31 05:42:20 +00:00
|
|
|
//
|
|
|
|
// Copyright (c) 2013-2021 Winlin
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
2015-09-24 09:20:04 +00:00
|
|
|
|
2017-01-18 08:23:59 +00:00
|
|
|
#ifndef SRS_KERNEL_BALANCE_HPP
|
|
|
|
#define SRS_KERNEL_BALANCE_HPP
|
2015-09-24 09:20:04 +00:00
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
|
|
|
#include <vector>
|
2015-09-24 09:54:58 +00:00
|
|
|
#include <string>
|
2015-09-24 09:20:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the round-robin load balance algorithm,
|
2019-10-03 04:45:38 +00:00
|
|
|
* used for edge pull and other multiple server feature.
|
2015-09-24 09:20:04 +00:00
|
|
|
*/
|
|
|
|
class SrsLbRoundRobin
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// current selected index.
|
|
|
|
int index;
|
|
|
|
// total scheduled count.
|
2017-01-30 09:32:18 +00:00
|
|
|
uint32_t count;
|
2015-09-24 09:54:58 +00:00
|
|
|
// current selected server.
|
|
|
|
std::string elem;
|
2015-09-24 09:20:04 +00:00
|
|
|
public:
|
|
|
|
SrsLbRoundRobin();
|
|
|
|
virtual ~SrsLbRoundRobin();
|
|
|
|
public:
|
2017-01-30 09:32:18 +00:00
|
|
|
virtual uint32_t current();
|
2015-09-24 09:54:58 +00:00
|
|
|
virtual std::string selected();
|
|
|
|
virtual std::string select(const std::vector<std::string>& servers);
|
2015-09-24 09:20:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|