Commit 36e1e0f5 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #28529: daemon: halve boolean port array

Since we force RTP to be on even ports, we only need half as many
booleans to keep track of what ports are in use.
parent 9a2da0bb
...@@ -66,7 +66,8 @@ const char *const TRUE_STR = "true"; ...@@ -66,7 +66,8 @@ const char *const TRUE_STR = "true";
const char *const FALSE_STR = "false"; const char *const FALSE_STR = "false";
} }
bool SIPAccount::portsInUse_[MAX_PORT]; // we force RTP ports to be even, so we only need HALF_MAX_PORT booleans
bool SIPAccount::portsInUse_[HALF_MAX_PORT];
SIPAccount::SIPAccount(const std::string& accountID) SIPAccount::SIPAccount(const std::string& accountID)
: Account(accountID) : Account(accountID)
...@@ -1396,16 +1397,16 @@ SIPAccount::getRandomEvenNumber(const std::pair<uint16_t, uint16_t> &range) ...@@ -1396,16 +1397,16 @@ SIPAccount::getRandomEvenNumber(const std::pair<uint16_t, uint16_t> &range)
uint16_t result; uint16_t result;
do { do {
result = 2 * (halfLower + rand() % (halfUpper - halfLower + 1)); result = 2 * (halfLower + rand() % (halfUpper - halfLower + 1));
} while (portsInUse_[result]); } while (portsInUse_[result / 2]);
portsInUse_[result] = true; portsInUse_[result / 2] = true;
return result; return result;
} }
void void
SIPAccount::releasePort(uint16_t port) SIPAccount::releasePort(uint16_t port)
{ {
portsInUse_[port] = false; portsInUse_[port / 2] = false;
} }
uint16_t uint16_t
......
...@@ -105,6 +105,7 @@ class SIPVoIPLink; ...@@ -105,6 +105,7 @@ class SIPVoIPLink;
* @brief A SIP Account specify SIP specific functions and object = SIPCall/SIPVoIPLink) * @brief A SIP Account specify SIP specific functions and object = SIPCall/SIPVoIPLink)
*/ */
enum {MAX_PORT = 65536}; enum {MAX_PORT = 65536};
enum {HALF_MAX_PORT = MAX_PORT / 2};
class SIPAccount : public Account { class SIPAccount : public Account {
public: public:
...@@ -789,7 +790,7 @@ class SIPAccount : public Account { ...@@ -789,7 +790,7 @@ class SIPAccount : public Account {
*/ */
std::pair<uint16_t, uint16_t> videoPortRange_; std::pair<uint16_t, uint16_t> videoPortRange_;
#endif #endif
static bool portsInUse_[MAX_PORT]; static bool portsInUse_[HALF_MAX_PORT];
static uint16_t getRandomEvenNumber(const std::pair<uint16_t, uint16_t> &range); static uint16_t getRandomEvenNumber(const std::pair<uint16_t, uint16_t> &range);
}; };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment