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

logger: just use debug/warn/error levels in both Node and C++.

上级 bb440ecd
...@@ -9,9 +9,34 @@ class Request ...@@ -9,9 +9,34 @@ class Request
{ {
logger.debug('constructor() [method:%s]', method); logger.debug('constructor() [method:%s]', method);
this.id = randomString({ length: 8 }).toLowerCase(); this._id = randomString({ length: 8 }).toLowerCase();
this.method = method; this._method = method;
this.data = data || {}; this._data = data || {};
}
serialize()
{
return JSON.stringify(
{
method : this._method,
id : this._id,
data : this._data
});
}
get method()
{
return this._method;
}
get id()
{
return this._id;
}
get data()
{
return this._data;
} }
} }
......
...@@ -5,6 +5,9 @@ const netstring = require('netstring'); ...@@ -5,6 +5,9 @@ const netstring = require('netstring');
const logger = require('../logger')('Channel'); const logger = require('../logger')('Channel');
const Request = require('./Request'); const Request = require('./Request');
// Max time waiting for a response from the worker subprocess
const REQUEST_TIMEOUT = 4000; // TODO: set it properly
class Channel extends EventEmitter class Channel extends EventEmitter
{ {
constructor(socket) constructor(socket)
...@@ -16,8 +19,25 @@ class Channel extends EventEmitter ...@@ -16,8 +19,25 @@ class Channel extends EventEmitter
// Unix Socket instance // Unix Socket instance
this._socket = socket; this._socket = socket;
// Map of sent requests waiting for a response this._pendingSent = new Map();
this._pendingRequests = new Map();
// TODO: read Channel responses/notifications from the worker
this._socket.on('data', (buffer) =>
{
logger.debug('data received from the socket: %s', buffer.toString('utf8'));
});
}
close()
{
logger.debug('close()');
// Close every pending sent
this._pendingSent.forEach(sent => sent.close());
// Close the UnixStream socket
this._socket.destroy();
} }
sendRequest(method, data) sendRequest(method, data)
...@@ -25,14 +45,74 @@ class Channel extends EventEmitter ...@@ -25,14 +45,74 @@ class Channel extends EventEmitter
logger.debug('sendRequest() [method:%s]', method); logger.debug('sendRequest() [method:%s]', method);
let request = new Request(method, data); let request = new Request(method, data);
let json = JSON.stringify(request); let ns = netstring.nsWrite(request.serialize());
let ns = netstring.nsWrite(json); let promise;
logger.debug('nsWriteLength: %s', netstring.nsWriteLength(Buffer.byteLength(json)));
// TODO: This may raise if closed or remote side ended // This may raise if closed or remote side ended
try
{
this._socket.write(ns); this._socket.write(ns);
} }
catch (error)
{
return Promise.reject(error);
}
promise = new Promise((pResolve, pReject) =>
{
let sent =
{
resolve: (data) =>
{
if (!this._pendingSent.delete(request.id))
{
return;
}
clearTimeout(sent.timer);
pResolve(data);
},
reject: (error) =>
{
if (!this._pendingSent.delete(request.id))
{
return;
}
clearTimeout(sent.timer);
pReject(error);
},
timer: setTimeout(() =>
{
if (!this._pendingSent.delete(request.id))
{
return;
}
let error = new Error('timeout');
error.name = 'TIMEOUT';
pReject(error);
}, REQUEST_TIMEOUT),
close: () =>
{
let error = new Error('channel closed');
error.name = 'CHANNEL_CLOSED';
clearTimeout(sent.timer);
pReject(error);
}
};
// Add sent stuff to the Map
this._pendingSent.set(request.id, sent);
});
return promise;
}
} }
module.exports = Channel; module.exports = Channel;
...@@ -24,19 +24,34 @@ class Room extends EventEmitter ...@@ -24,19 +24,34 @@ class Room extends EventEmitter
let data = let data =
{ {
foo : 'lalala', foo : 'lalala',
bar : 1234 baz : 4321,
bar : 'œæ€😤😮😱Ω∑©'
}; };
this._channel.sendRequest('createRoom', data); // setInterval(() => {
this._channel.sendRequest('createRoom', data)
.then(data =>
{
logger.debug('"createRoom" command succeeded: %s', data); // TODO: TMP
this._status = STATUS.OPEN;
})
.catch(error =>
{
logger.error('"createRoom" command failed: %s', error);
// TODO: enable
// this.close(error);
});
// }, 50);
} }
close() close(error)
{ {
logger.debug('close()'); logger.debug('close()');
this._status = STATUS.CLOSED; this._status = STATUS.CLOSED;
this.emit('close'); this.emit('close', error);
} }
} }
......
...@@ -10,9 +10,11 @@ const Room = require('./Room'); ...@@ -10,9 +10,11 @@ const Room = require('./Room');
const WORKER_BIN_PATH = path.join(__dirname, '..', 'worker', 'bin', 'mediasoup-worker'); const WORKER_BIN_PATH = path.join(__dirname, '..', 'worker', 'bin', 'mediasoup-worker');
const CHANNEL_FD = 3; const CHANNEL_FD = 3;
const LOGGER_FD = 4;
// Set an env variable to tell childs which the Channel FD is // Set environtemt variables for the worker
process.env.MEDIASOUP_CHANNEL_FD = String(CHANNEL_FD); process.env.MEDIASOUP_CHANNEL_FD = String(CHANNEL_FD);
process.env.MEDIASOUP_LOGGER_FD = String(LOGGER_FD);
class Worker extends EventEmitter class Worker extends EventEmitter
{ {
...@@ -26,7 +28,15 @@ class Worker extends EventEmitter ...@@ -26,7 +28,15 @@ class Worker extends EventEmitter
let spawnOptions = let spawnOptions =
{ {
detached : false, detached : false,
stdio : [ 'pipe', 'pipe', 'pipe', 'pipe' ] /*
* fd 0 (stdin) : Just ignore it
* fd 1 (stdout) : Pipe it for 3rd libraries in the worker
* that logs their own stuff
* fd 2 (stderr) : Same as stdout
* fd 3 (channel) : Channel fd
* fd 4 (logger) : Logger fd
*/
stdio : [ 'ignore', 'pipe', 'pipe', 'pipe', 'pipe' ]
}; };
// Create the mediasoup-worker child process // Create the mediasoup-worker child process
...@@ -38,18 +48,37 @@ class Worker extends EventEmitter ...@@ -38,18 +48,37 @@ class Worker extends EventEmitter
// Set of Room instances // Set of Room instances
this._rooms = new Set(); this._rooms = new Set();
// Set child process events // Set worker logger
this._child.stdio[LOGGER_FD].on('data', (buffer) =>
this._child.stdout.on('data', (buffer) =>
{ {
buffer.toString('utf8').split('\n').forEach((line) => line && logger.debug(line)); // logger.error('--------- ondata:\n', buffer.toString('utf8'));
}); buffer.toString('utf8').split('\f').forEach((line) =>
{
this._child.stderr.on('data', (buffer) => switch (line[0])
{ {
buffer.toString('utf8').split('\n').forEach((line) => line && logger.error(line)); case undefined:
break;
// MS_DEBUG & MS_TRACE
case 'D':
logger.debug(line.slice(1));
break;
// MS_WARN
case 'W':
logger.warn(line.slice(1));
break;
// MS_ERROR
case 'E':
logger.error(line.slice(1));
break;
// Multiline logs, so use the latest level
default:
logger.warn(`unexpected log: ${line}`);
}
});
}); });
// Set child process events
this._child.on('exit', (code, signal) => this._child.on('exit', (code, signal) =>
{ {
// TODO: different log depending on code/signal // TODO: different log depending on code/signal
...@@ -71,8 +100,13 @@ class Worker extends EventEmitter ...@@ -71,8 +100,13 @@ class Worker extends EventEmitter
logger.debug('close()'); logger.debug('close()');
// Kill child // Kill child
this._child.removeAllListeners('exit');
this._child.removeAllListeners('error');
this._child.kill('SIGTERM'); this._child.kill('SIGTERM');
// Close the Channel instance
this._channel.close();
// Close every Room // Close every Room
this._rooms.forEach(room => room.close()); this._rooms.forEach(room => room.close());
......
...@@ -20,17 +20,16 @@ namespace Channel ...@@ -20,17 +20,16 @@ namespace Channel
UnixStreamSocket(Listener* listener, int fd); UnixStreamSocket(Listener* listener, int fd);
virtual ~UnixStreamSocket(); virtual ~UnixStreamSocket();
private:
void Reset();
/* Pure virtual methods inherited from ::UnixStreamSocket. */ /* Pure virtual methods inherited from ::UnixStreamSocket. */
public: public:
virtual void userOnUnixStreamRead(const MS_BYTE* data, size_t len) override; virtual void userOnUnixStreamRead() override;
virtual void userOnUnixStreamSocketClosed(bool is_closed_by_peer) override; virtual void userOnUnixStreamSocketClosed(bool is_closed_by_peer) override;
private: private:
// Passed by argument: // Passed by argument:
Listener* listener = nullptr; Listener* listener = nullptr;
// Others:
size_t msgStart = 0; // Where the latest message starts.
}; };
} }
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
#include "common.h" #include "common.h"
#include "Settings.h" #include "Settings.h"
#include <string> #include <string>
#include <cstdio> // stdout, stderr, fflush() #include <cstdio> // stdout, stderr, dprintf()
#include <cstring> #include <cstring>
#include <cstdlib> // std::_Exit(), std::abort() #include <cstdlib> // std::_Exit(), std::abort(), std::genenv()
#include <uv.h> #include <uv.h>
/* /*
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
* *
* - MS_TRACE() Shows current file/line/class/function. * - MS_TRACE() Shows current file/line/class/function.
* - MS_DEBUG(...) * - MS_DEBUG(...)
* - MS_INFO(...)
* - MS_WARN(...) * - MS_WARN(...)
* - MS_ERROR(...) * - MS_ERROR(...)
* - MS_ABORT(...) * - MS_ABORT(...)
...@@ -51,6 +50,7 @@ public: ...@@ -51,6 +50,7 @@ public:
public: public:
static std::string id; static std::string id;
static int fd;
}; };
/* Inline static methods. */ /* Inline static methods. */
...@@ -63,6 +63,8 @@ bool Logger::HasDebugLevel() ...@@ -63,6 +63,8 @@ bool Logger::HasDebugLevel()
// NOTE: Each file including Logger.h MUST define its own MS_CLASS macro. // NOTE: Each file including Logger.h MUST define its own MS_CLASS macro.
#define _MS_LOG_SEPARATOR_CHAR "\f"
#ifdef MS_DEVEL #ifdef MS_DEVEL
#define _MS_LOG_STR "[%s] %s:%d | %s::%s()" #define _MS_LOG_STR "[%s] %s:%d | %s::%s()"
#define _MS_LOG_STR_DESC _MS_LOG_STR " | " #define _MS_LOG_STR_DESC _MS_LOG_STR " | "
...@@ -74,23 +76,11 @@ bool Logger::HasDebugLevel() ...@@ -74,23 +76,11 @@ bool Logger::HasDebugLevel()
#define _MS_LOG_ARG ("id:" + Logger::id).c_str(), MS_CLASS, __FUNCTION__ #define _MS_LOG_ARG ("id:" + Logger::id).c_str(), MS_CLASS, __FUNCTION__
#endif #endif
#define _MS_TO_STDOUT() \
std::fprintf(stdout, _MS_LOG_STR "\n", _MS_LOG_ARG); \
fflush(stdout);
#define _MS_TO_STDOUT_DESC(desc, ...) \
std::fprintf(stdout, _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \
fflush(stdout); \
#define _MS_TO_STDERR_DESC(desc, ...) \
std::fprintf(stderr, _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \
fflush(stderr); \
#ifdef MS_DEVEL #ifdef MS_DEVEL
#define MS_TRACE() \ #define MS_TRACE() \
do \ do \
{ \ { \
_MS_TO_STDOUT(); \ dprintf(Logger::fd, "D" _MS_LOG_STR _MS_LOG_SEPARATOR_CHAR, _MS_LOG_ARG); \
} \ } \
while (0) while (0)
#else #else
...@@ -102,17 +92,7 @@ bool Logger::HasDebugLevel() ...@@ -102,17 +92,7 @@ bool Logger::HasDebugLevel()
{ \ { \
if (MS_LOG_LEVEL_DEBUG == MS_GET_LOG_LEVEL) \ if (MS_LOG_LEVEL_DEBUG == MS_GET_LOG_LEVEL) \
{ \ { \
_MS_TO_STDOUT_DESC(desc, ##__VA_ARGS__); \ dprintf(Logger::fd, "D" _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR, _MS_LOG_ARG, ##__VA_ARGS__); \
} \
} \
while (0)
#define MS_INFO(desc, ...) \
do \
{ \
if (MS_LOG_LEVEL_INFO <= MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC(desc, ##__VA_ARGS__); \
} \ } \
} \ } \
while (0) while (0)
...@@ -122,7 +102,7 @@ bool Logger::HasDebugLevel() ...@@ -122,7 +102,7 @@ bool Logger::HasDebugLevel()
{ \ { \
if (MS_LOG_LEVEL_WARN <= MS_GET_LOG_LEVEL) \ if (MS_LOG_LEVEL_WARN <= MS_GET_LOG_LEVEL) \
{ \ { \
_MS_TO_STDERR_DESC(desc, ##__VA_ARGS__); \ dprintf(Logger::fd, "W" _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR, _MS_LOG_ARG, ##__VA_ARGS__); \
} \ } \
} \ } \
while (0) while (0)
...@@ -130,14 +110,14 @@ bool Logger::HasDebugLevel() ...@@ -130,14 +110,14 @@ bool Logger::HasDebugLevel()
#define MS_ERROR(desc, ...) \ #define MS_ERROR(desc, ...) \
do \ do \
{ \ { \
_MS_TO_STDERR_DESC(desc, ##__VA_ARGS__); \ dprintf(Logger::fd, "E" _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR, _MS_LOG_ARG, ##__VA_ARGS__); \
} \ } \
while (0) while (0)
#define MS_EXIT_SUCCESS(desc, ...) \ #define MS_EXIT_SUCCESS(desc, ...) \
do \ do \
{ \ { \
MS_INFO("SUCCESS EXIT | " desc, ##__VA_ARGS__); \ MS_DEBUG("SUCCESS EXIT | " desc, ##__VA_ARGS__); \
std::_Exit(EXIT_SUCCESS); \ std::_Exit(EXIT_SUCCESS); \
} \ } \
while (0) while (0)
......
...@@ -26,7 +26,7 @@ namespace RTC ...@@ -26,7 +26,7 @@ namespace RTC
/* Pure virtual methods inherited from ::TCPConnection. */ /* Pure virtual methods inherited from ::TCPConnection. */
public: public:
virtual void userOnTCPConnectionRead(const MS_BYTE* data, size_t len) override; virtual void userOnTCPConnectionRead() override;
private: private:
// Passed by argument: // Passed by argument:
......
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
#define MS_APP_NAME "mediasoup" #define MS_APP_NAME "mediasoup"
#define MS_PROCESS_NAME "mediasoup-worker" #define MS_PROCESS_NAME "mediasoup-worker"
#define MS_LOG_LEVEL_DEBUG 3 #define MS_LOG_LEVEL_DEBUG 2
#define MS_LOG_LEVEL_INFO 2
#define MS_LOG_LEVEL_WARN 1 #define MS_LOG_LEVEL_WARN 1
#define MS_LOG_LEVEL_ERROR 0 #define MS_LOG_LEVEL_ERROR 0
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
/* Pure virtual methods that must be implemented by the subclass. */ /* Pure virtual methods that must be implemented by the subclass. */
protected: protected:
virtual void userOnTCPConnectionRead(const MS_BYTE* data, size_t len) = 0; virtual void userOnTCPConnectionRead() = 0;
private: private:
// Allocated by this: // Allocated by this:
......
...@@ -37,7 +37,7 @@ public: ...@@ -37,7 +37,7 @@ public:
/* Pure virtual methods that must be implemented by the subclass. */ /* Pure virtual methods that must be implemented by the subclass. */
protected: protected:
virtual void userOnUnixStreamRead(const MS_BYTE* data, size_t len) = 0; virtual void userOnUnixStreamRead() = 0;
virtual void userOnUnixStreamSocketClosed(bool is_closed_by_peer) = 0; virtual void userOnUnixStreamSocketClosed(bool is_closed_by_peer) = 0;
private: private:
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "Logger.h" #include "Logger.h"
#include <json/json.h> #include <json/json.h>
#include <netstring.h> #include <netstring.h>
#include <cstring> // std::memmove()
#
#define MESSAGE_MAX_SIZE 65536 // TODO: set proper buffer size #define MESSAGE_MAX_SIZE 65536 // TODO: set proper buffer size
namespace Channel namespace Channel
...@@ -23,81 +24,136 @@ namespace Channel ...@@ -23,81 +24,136 @@ namespace Channel
MS_TRACE(); MS_TRACE();
} }
void UnixStreamSocket::Reset() void UnixStreamSocket::userOnUnixStreamRead()
{ {
MS_TRACE(); MS_TRACE();
// reset parsing stuff, dataLen, etc // Be ready to parse more than a single message in a single TCP chunk.
} while (true)
void UnixStreamSocket::userOnUnixStreamRead(const MS_BYTE* data, size_t len)
{ {
MS_TRACE(); size_t read_len = this->bufferDataLen - this->msgStart;
char* json_start = nullptr;
std::string kk((const char*)data, len); size_t json_len;
int ns_ret = netstring_read((char*)(this->buffer + this->msgStart), read_len,
MS_WARN("---------- readed data: %s", kk.c_str()); &json_start, &json_len);
this->bufferDataLen = 0; std::string kk1((const char*)(this->buffer + this->msgStart), read_len);
MS_WARN("* loop data: <%s>", kk1.c_str());
char *ns_start = nullptr;
size_t ns_length;
int ns_ret = netstring_read((char *)data, len, &ns_start, &ns_length);
if (ns_ret != 0) if (ns_ret != 0)
{ {
switch (ns_ret) switch (ns_ret)
{ {
case NETSTRING_ERROR_TOO_SHORT: case NETSTRING_ERROR_TOO_SHORT:
MS_DEBUG("received netstring is too short, waiting for more data"); MS_ERROR("received netstring is too short, need more data");
// Check if the buffer is full.
if (this->bufferDataLen == this->bufferSize)
{
// First case: the uncomplete message does not begin at position 0 of
// the buffer, so move the uncomplete message to the position 0.
if (this->msgStart != 0)
{
MS_ERROR("no more space in the buffer, moving parsed bytes to the beginning of the buffer and waiting for more data");
std::memmove(this->buffer, this->buffer + this->msgStart, read_len);
this->msgStart = 0;
this->bufferDataLen = read_len;
}
// Second case: the uncomplete message begins at position 0 of the buffer.
// The message is too big, so discard it.
else
{
MS_ERROR("no more space in the buffer for the unfinished message being parsed, discarding it");
this->msgStart = 0;
this->bufferDataLen = 0;
}
}
// Otherwise the buffer is not full, just wait.
// Exit the parsing loop.
return; return;
case NETSTRING_ERROR_TOO_LONG: case NETSTRING_ERROR_TOO_LONG:
MS_ERROR("NETSTRING_ERROR_TOO_LONG"); MS_ERROR("NETSTRING_ERROR_TOO_LONG");
break; break;
case NETSTRING_ERROR_NO_COLON: case NETSTRING_ERROR_NO_COLON:
MS_ERROR("NETSTRING_ERROR_NO_COLON"); MS_ERROR("NETSTRING_ERROR_NO_COLON");
break; break;
case NETSTRING_ERROR_NO_COMMA: case NETSTRING_ERROR_NO_COMMA:
MS_ERROR("NETSTRING_ERROR_NO_COMMA"); MS_ERROR("NETSTRING_ERROR_NO_COMMA");
break; break;
case NETSTRING_ERROR_LEADING_ZERO: case NETSTRING_ERROR_LEADING_ZERO:
MS_ERROR("NETSTRING_ERROR_LEADING_ZERO"); MS_ERROR("NETSTRING_ERROR_LEADING_ZERO");
break; break;
case NETSTRING_ERROR_NO_LENGTH: case NETSTRING_ERROR_NO_LENGTH:
MS_ERROR("NETSTRING_ERROR_NO_LENGTH"); MS_ERROR("NETSTRING_ERROR_NO_LENGTH");
break; break;
} }
Reset(); // Error, so reset and exit the parsing loop.
this->msgStart = 0;
this->bufferDataLen = 0;
return; return;
} }
// If here it means that json_start points to the beginning of a JSON string
// with json_len bytes length, so recalculate read_len.
read_len = (const MS_BYTE*)json_start - (this->buffer + this->msgStart) + json_len + 1;
Json::Value json; Json::Value json;
Json::Reader reader; Json::Reader reader;
if (reader.parse((const char*)ns_start, (const char*)ns_start + ns_length, json)) if (reader.parse((const char*)json_start, (const char*)json_start + json_len, json))
{ {
MS_INFO("jsoncpp: IT IS VALID JSON:\n\n%s\n", json.toStyledString().c_str()); MS_DEBUG("jsoncpp: IT IS VALID JSON:\n%s", json.toStyledString().c_str());
// MS_DEBUG("jsoncpp: method : %s", json["method"].asCString());
// MS_DEBUG("jsoncpp: room.id : %d", json["room"]["id"].asInt());
// MS_DEBUG("jsoncpp: room.closed : %s", json["room"]["closed"].asBool() ? "true" : "false");
// if (json["method"].isString()) Write("VALID JSON MAN !!!!:");
// MS_DEBUG("jsoncpp: method is a string"); Write(json.toStyledString());
// if (!json.isMember("kk"))
// MS_DEBUG("jsoncpp: kk is not member");
// if (json["parent"]["foo"]["bar"].isNull()) // TODO: process it
// MS_DEBUG("jsoncpp: parent.foo.bar is null");
} }
else else
{ {
MS_ERROR("jsoncpp: INVALID JSON !!!!"); MS_ERROR("jsoncpp: INVALID JSON !!!!");
MS_ASSERT(1 != 2, "--------- INVALID JSON !!!");
}
// If there is no more space available in the buffer and that is because
// the latest parsed message filled it, then empty the full buffer.
if ((this->msgStart + read_len) == this->bufferSize)
{
MS_ERROR("no more space in the buffer, emptying the buffer data");
this->msgStart = 0;
this->bufferDataLen = 0;
}
// If there is still space in the buffer, set the beginning of the next
// parsing to the next position after the parsed message.
else
{
this->msgStart += read_len;
}
// If there is more data in the buffer after the parsed message
// then parse again. Otherwise break here and wait for more data.
if (this->bufferDataLen > this->msgStart)
{
MS_ERROR("there is more data after the parsed message, continue parsing");
continue;
}
else
{
break;
}
} }
} }
......
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
/* Static variables. */ /* Static variables. */
std::string Logger::id; std::string Logger::id;
int Logger::fd;
/* Static methods. */ /* Static methods. */
void Logger::Init(const std::string id) void Logger::Init(const std::string id)
{ {
Logger::id = id; Logger::id = id;
Logger::fd = std::stoi(std::getenv("MEDIASOUP_LOGGER_FD"));
MS_TRACE(); MS_TRACE();
} }
...@@ -36,7 +36,7 @@ namespace RTC ...@@ -36,7 +36,7 @@ namespace RTC
{ {
RTC::UDPSocket* socket = RTC::UDPSocket::New(AF_INET); RTC::UDPSocket* socket = RTC::UDPSocket::New(AF_INET);
this->transport->AddUDPSocket(socket); this->transport->AddUDPSocket(socket);
MS_INFO("---- TEST: transport listens in IPv4 UDP '%s' : %u", socket->GetLocalIP().c_str(), socket->GetLocalPort()); MS_WARN("---- TEST: transport listens in IPv4 UDP '%s' : %u", socket->GetLocalIP().c_str(), socket->GetLocalPort());
} }
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
...@@ -47,7 +47,7 @@ namespace RTC ...@@ -47,7 +47,7 @@ namespace RTC
{ {
RTC::TCPServer* server = RTC::TCPServer::New(AF_INET); RTC::TCPServer* server = RTC::TCPServer::New(AF_INET);
this->transport->AddTCPServer(server); this->transport->AddTCPServer(server);
MS_INFO("---- TEST: transport listens in IPv4 TCP '%s' : %u", server->GetLocalIP().c_str(), server->GetLocalPort()); MS_WARN("---- TEST: transport listens in IPv4 TCP '%s' : %u", server->GetLocalIP().c_str(), server->GetLocalPort());
} }
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
......
...@@ -25,12 +25,13 @@ namespace RTC ...@@ -25,12 +25,13 @@ namespace RTC
MS_TRACE(); MS_TRACE();
} }
void TCPConnection::userOnTCPConnectionRead(const MS_BYTE* data, size_t len) void TCPConnection::userOnTCPConnectionRead()
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG("%zu bytes received [local: %s : %u | remote: %s : %u]", len, MS_DEBUG("data received [local: %s : %u | remote: %s : %u]",
GetLocalIP().c_str(), (unsigned int)GetLocalPort(), GetPeerIP().c_str(), (unsigned int)GetPeerPort()); GetLocalIP().c_str(), (unsigned int)GetLocalPort(),
GetPeerIP().c_str(), (unsigned int)GetPeerPort());
/* /*
* Framing RFC 4571 * Framing RFC 4571
......
...@@ -27,14 +27,12 @@ struct Settings::Configuration Settings::configuration; ...@@ -27,14 +27,12 @@ struct Settings::Configuration Settings::configuration;
std::map<std::string, unsigned int> Settings::string2LogLevel = std::map<std::string, unsigned int> Settings::string2LogLevel =
{ {
{ "debug", MS_LOG_LEVEL_DEBUG }, { "debug", MS_LOG_LEVEL_DEBUG },
{ "info", MS_LOG_LEVEL_INFO },
{ "warn", MS_LOG_LEVEL_WARN }, { "warn", MS_LOG_LEVEL_WARN },
{ "error", MS_LOG_LEVEL_ERROR } { "error", MS_LOG_LEVEL_ERROR }
}; };
std::map<unsigned int, std::string> Settings::logLevel2String = std::map<unsigned int, std::string> Settings::logLevel2String =
{ {
{ MS_LOG_LEVEL_DEBUG, "debug" }, { MS_LOG_LEVEL_DEBUG, "debug" },
{ MS_LOG_LEVEL_INFO, "info" },
{ MS_LOG_LEVEL_WARN, "warn" }, { MS_LOG_LEVEL_WARN, "warn" },
{ MS_LOG_LEVEL_ERROR, "error" } { MS_LOG_LEVEL_ERROR, "error" }
}; };
......
...@@ -352,7 +352,7 @@ void TCPConnection::onUvRead(ssize_t nread, const uv_buf_t* buf) ...@@ -352,7 +352,7 @@ void TCPConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
this->bufferDataLen += (size_t)nread; this->bufferDataLen += (size_t)nread;
// Notify the subclass. // Notify the subclass.
userOnTCPConnectionRead((MS_BYTE*)buf->base, nread); userOnTCPConnectionRead();
} }
// Client disconneted. // Client disconneted.
else if (nread == UV_EOF || nread == UV_ECONNRESET) else if (nread == UV_EOF || nread == UV_ECONNRESET)
...@@ -366,7 +366,7 @@ void TCPConnection::onUvRead(ssize_t nread, const uv_buf_t* buf) ...@@ -366,7 +366,7 @@ void TCPConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
// Some error. // Some error.
else else
{ {
MS_INFO("read error: %s | closing the connection", uv_strerror(nread)); MS_DEBUG("read error: %s | closing the connection", uv_strerror(nread));
this->hasError = true; this->hasError = true;
// Close server side of the connection. // Close server side of the connection.
...@@ -389,7 +389,7 @@ void TCPConnection::onUvWriteError(int error) ...@@ -389,7 +389,7 @@ void TCPConnection::onUvWriteError(int error)
} }
else else
{ {
MS_INFO("write error: %s | closing the connection", uv_strerror(error)); MS_DEBUG("write error: %s | closing the connection", uv_strerror(error));
this->hasError = true; this->hasError = true;
} }
...@@ -406,7 +406,7 @@ void TCPConnection::onUvShutdown(uv_shutdown_t* req, int status) ...@@ -406,7 +406,7 @@ void TCPConnection::onUvShutdown(uv_shutdown_t* req, int status)
if (status == UV_EPIPE || status == UV_ENOTCONN || status == UV_ECANCELED) if (status == UV_EPIPE || status == UV_ENOTCONN || status == UV_ECANCELED)
MS_DEBUG("shutdown error: %s", uv_strerror(status)); MS_DEBUG("shutdown error: %s", uv_strerror(status));
else if (status) else if (status)
MS_INFO("shutdown error: %s", uv_strerror(status)); MS_DEBUG("shutdown error: %s", uv_strerror(status));
// Now do close the handle. // Now do close the handle.
uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close);
......
...@@ -344,7 +344,7 @@ void UDPSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad ...@@ -344,7 +344,7 @@ void UDPSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad
// Some error. // Some error.
else else
{ {
MS_INFO("read error: %s", uv_strerror(nread)); MS_DEBUG("read error: %s", uv_strerror(nread));
} }
} }
...@@ -356,7 +356,7 @@ void UDPSocket::onUvSendError(int error) ...@@ -356,7 +356,7 @@ void UDPSocket::onUvSendError(int error)
if (this->isClosing) if (this->isClosing)
return; return;
MS_INFO("send error: %s", uv_strerror(error)); MS_DEBUG("send error: %s", uv_strerror(error));
} }
inline inline
......
...@@ -240,7 +240,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf) ...@@ -240,7 +240,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf)
this->bufferDataLen += (size_t)nread; this->bufferDataLen += (size_t)nread;
// Notify the subclass. // Notify the subclass.
userOnUnixStreamRead((MS_BYTE*)buf->base, nread); userOnUnixStreamRead();
} }
// Peer disconneted. // Peer disconneted.
else if (nread == UV_EOF || nread == UV_ECONNRESET) else if (nread == UV_EOF || nread == UV_ECONNRESET)
...@@ -254,7 +254,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf) ...@@ -254,7 +254,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf)
// Some error. // Some error.
else else
{ {
MS_INFO("read error: %s | closing the pipe", uv_strerror(nread)); MS_DEBUG("read error: %s | closing the pipe", uv_strerror(nread));
this->hasError = true; this->hasError = true;
// Close the socket. // Close the socket.
...@@ -277,7 +277,7 @@ void UnixStreamSocket::onUvWriteError(int error) ...@@ -277,7 +277,7 @@ void UnixStreamSocket::onUvWriteError(int error)
} }
else else
{ {
MS_INFO("write error: %s | closing the pipe", uv_strerror(error)); MS_DEBUG("write error: %s | closing the pipe", uv_strerror(error));
this->hasError = true; this->hasError = true;
} }
...@@ -294,7 +294,7 @@ void UnixStreamSocket::onUvShutdown(uv_shutdown_t* req, int status) ...@@ -294,7 +294,7 @@ void UnixStreamSocket::onUvShutdown(uv_shutdown_t* req, int status)
if (status == UV_EPIPE || status == UV_ENOTCONN || status == UV_ECANCELED) if (status == UV_EPIPE || status == UV_ENOTCONN || status == UV_ECANCELED)
MS_DEBUG("shutdown error: %s", uv_strerror(status)); MS_DEBUG("shutdown error: %s", uv_strerror(status));
else if (status) else if (status)
MS_INFO("shutdown error: %s", uv_strerror(status)); MS_DEBUG("shutdown error: %s", uv_strerror(status));
// Now do close the handle. // Now do close the handle.
uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close);
......
...@@ -53,7 +53,7 @@ int main(int argc, char* argv[], char** envp) ...@@ -53,7 +53,7 @@ int main(int argc, char* argv[], char** envp)
// Print configuration. // Print configuration.
Settings::PrintConfiguration(); Settings::PrintConfiguration();
MS_INFO("starting " MS_PROCESS_NAME " [pid:%ld]", (long)getpid()); MS_DEBUG("starting " MS_PROCESS_NAME " [pid:%ld]", (long)getpid());
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
MS_DEBUG("detected Little-Endian CPU"); MS_DEBUG("detected Little-Endian CPU");
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论