提交 9bc4d37a authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Distribute RTC ports between workers.

上级 b983c05e
...@@ -46,6 +46,12 @@ class Server extends EventEmitter ...@@ -46,6 +46,12 @@ class Server extends EventEmitter
if (options.rtcListenIPv6 === null || options.rtcListenIPv6 === undefined) if (options.rtcListenIPv6 === null || options.rtcListenIPv6 === undefined)
delete options.rtcListenIPv6; delete options.rtcListenIPv6;
if (!check.greaterOrEqual(options.rtcMinPort, 1024))
options.rtcMinPort = 10000;
if (!check.lessOrEqual(options.rtcMaxPort, 65535))
options.rtcMaxPort = 59999;
if (check.nonEmptyString(options.dtlsCertificateFile)) if (check.nonEmptyString(options.dtlsCertificateFile))
options.dtlsCertificateFile = path.resolve(options.dtlsCertificateFile); options.dtlsCertificateFile = path.resolve(options.dtlsCertificateFile);
...@@ -63,8 +69,28 @@ class Server extends EventEmitter ...@@ -63,8 +69,28 @@ class Server extends EventEmitter
{ {
let worker; let worker;
let workerId = serverId + '#' + i; let workerId = serverId + '#' + i;
let workerParameters = parameters.slice(0);
// Distribute RTC ports for each worker
let rtcMinPort = options.rtcMinPort;
let rtcMaxPort = options.rtcMaxPort;
let numPorts = Math.floor((rtcMaxPort - rtcMinPort) / numWorkers);
rtcMinPort = rtcMinPort + (numPorts * (i - 1));
rtcMaxPort = rtcMinPort + numPorts;
if (rtcMinPort % 2 !== 0)
rtcMinPort++;
if (rtcMaxPort % 2 === 0)
rtcMaxPort--;
workerParameters.push(`--rtcMinPort=${rtcMinPort}`);
workerParameters.push(`--rtcMaxPort=${rtcMaxPort}`);
worker = new Worker(workerId, parameters); // Create a Worker instance
worker = new Worker(workerId, workerParameters);
// Store the Worker instance and remove it when closed // Store the Worker instance and remove it when closed
// Also, if it is the latest Worker then close the Server // Also, if it is the latest Worker then close the Server
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "Logger.h" #include "Logger.h"
#include <string> #include <string>
#define MAX_BIND_ATTEMPTS 1000 // TODO: hack #define MAX_BIND_ATTEMPTS 20
#define MAX_TCP_CONNECTIONS_PER_SERVER 10 #define MAX_TCP_CONNECTIONS_PER_SERVER 10
/* Static methods for UV callbacks. */ /* Static methods for UV callbacks. */
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "Logger.h" #include "Logger.h"
#include <string> #include <string>
#define MAX_BIND_ATTEMPTS 1000 // TODO: hack #define MAX_BIND_ATTEMPTS 20
/* Static methods for UV callbacks. */ /* Static methods for UV callbacks. */
......
...@@ -17,11 +17,10 @@ ...@@ -17,11 +17,10 @@
#include "Logger.h" #include "Logger.h"
#include <map> #include <map>
#include <string> #include <string>
#include <iostream> // std::cout, std::cerr
#include <cstdlib> // std::_Exit(), std::genenv() #include <cstdlib> // std::_Exit(), std::genenv()
#include <csignal> // sigaction() #include <csignal> // sigaction()
#include <cerrno> #include <cerrno>
#include <unistd.h> // getpid() #include <unistd.h> // getpid(), usleep()
#include <uv.h> #include <uv.h>
static void init(); static void init();
...@@ -51,7 +50,8 @@ int main(int argc, char* argv[], char** envp) ...@@ -51,7 +50,8 @@ int main(int argc, char* argv[], char** envp)
} }
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
std::cerr << "failure exit: " << error.what() << std::endl; MS_ERROR("failed to start: %s", error.what());
usleep(100000);
std::_Exit(EXIT_FAILURE); std::_Exit(EXIT_FAILURE);
} }
...@@ -82,13 +82,14 @@ int main(int argc, char* argv[], char** envp) ...@@ -82,13 +82,14 @@ int main(int argc, char* argv[], char** envp)
Loop loop(channel); Loop loop(channel);
destroy(); destroy();
std::cout << "success exit" << std::endl; MS_DEBUG_STD("success exit");
std::_Exit(EXIT_SUCCESS); std::_Exit(EXIT_SUCCESS);
} }
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
destroy(); destroy();
std::cerr << "failure exit: " << error.what() << std::endl; MS_ERROR_STD("failure exit: %s", error.what());
usleep(100000);
std::_Exit(EXIT_FAILURE); std::_Exit(EXIT_FAILURE);
} }
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论