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

Cleanup

上级 180a19d5
......@@ -142,6 +142,18 @@ class Channel extends EventEmitter
this._socket.removeAllListeners('end');
this._socket.removeAllListeners('error');
// Destroy the socket after a while to allow pending incoming
// messages
setTimeout(() =>
{
try
{
this._socket.destroy();
}
catch (error)
{}
}, 250);
}
request(method, data)
......
......@@ -51,19 +51,19 @@ class Worker extends EventEmitter
this._child.stdout.on('data', (buffer) =>
{
buffer.toString('utf8').split('\f').forEach((line) =>
buffer.toString('utf8').split('\n').forEach((line) =>
{
if (line)
logger.debug(`mediasoup-worker's stdout [id:${id}]: ${line}`);
logger.debug(`mediasoup-worker's stdout: ${line}`);
});
});
this._child.stderr.on('data', (buffer) =>
{
buffer.toString('utf8').split('\f').forEach((line) =>
buffer.toString('utf8').split('\n').forEach((line) =>
{
if (line)
logger.error(`mediasoup-worker's stderr [id:${id}]: ${line}`);
logger.error(`mediasoup-worker's stderr: ${line}`);
});
});
......
......@@ -67,7 +67,7 @@ bool Logger::HasDebugLevel()
// NOTE: Each file including Logger.h MUST define its own MS_CLASS macro.
#define _MS_LOG_SEPARATOR_CHAR_STD "\f"
#define _MS_LOG_SEPARATOR_CHAR_STD "\n"
#ifdef MS_DEVEL
#define _MS_LOG_STR "[%s] %s:%d | %s::%s()"
......
......@@ -292,9 +292,7 @@ void Loop::onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* so
// pipe and then exit.
// If the pipe is remotely closed it means that mediasoup Node process
// abruptly died (SIGKILL?) so we must die.
MS_ERROR_STD("Channel remotely closed, killing myself");
this->channel = nullptr;
Close();
......
......@@ -26,33 +26,42 @@
static void init();
static void ignoreSignals();
static void destroy();
static void exitSuccess();
static void exitWithError();
int main(int argc, char* argv[], char** envp)
int main(int argc, char* argv[])
{
// Initialize libuv stuff (we need it for the Channel).
DepLibUV::ClassInit();
// Ensure we are called by our Node library.
if (argc == 1 || !std::getenv("MEDIASOUP_CHANNEL_FD"))
{
fprintf(stderr, "YOU ARE NOT MY REAL FATHER\n");
std::_Exit(EXIT_FAILURE);
}
std::string id = std::string(argv[1]);
int channelFd = std::stoi(std::getenv("MEDIASOUP_CHANNEL_FD"));
// Initialize libuv stuff (we need it for the Channel).
DepLibUV::ClassInit();
// Set the Channel socket (this will be handled and deleted by the Loop).
Channel::UnixStreamSocket* channel = new Channel::UnixStreamSocket(channelFd);
std::string id = std::string(argv[1]);
// Initialize the Logger.
Logger::Init(id, channel);
// Setup the configuration.
try
{
Settings::SetConfiguration(argc, argv);
}
catch (const MediaSoupError &error)
{
MS_ERROR("failed to start: %s", error.what());
usleep(100000);
std::_Exit(EXIT_FAILURE);
MS_ERROR("configuration error: %s", error.what());
exitWithError();
}
// Print configuration.
// Print the effective configuration.
Settings::PrintConfiguration();
MS_DEBUG("starting " MS_PROCESS_NAME " [pid:%ld]", (long)getpid());
......@@ -80,14 +89,13 @@ int main(int argc, char* argv[], char** envp)
destroy();
MS_DEBUG_STD("success exit");
std::_Exit(EXIT_SUCCESS);
exitSuccess();
}
catch (const MediaSoupError &error)
{
destroy();
MS_ERROR_STD("failure exit: %s", error.what());
usleep(100000);
std::_Exit(EXIT_FAILURE);
exitWithError();
}
}
......@@ -154,3 +162,21 @@ void destroy()
RTC::DTLSAgent::ClassDestroy();
Utils::Crypto::ClassDestroy();
}
void exitSuccess()
{
// Wait a bit so peding messages to stdout/Channel arrive to the main process.
usleep(100000);
// And exit with success status.
std::_Exit(EXIT_SUCCESS);
}
void exitWithError()
{
// Wait a bit so peding messages to stderr arrive to the main process.
usleep(100000);
// And exit with error status.
std::_Exit(EXIT_FAILURE);
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论