Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
ca8f4364
提交
ca8f4364
authored
12月 18, 2015
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
logger: just use debug/warn/error levels in both Node and C++.
上级
bb440ecd
隐藏空白字符变更
内嵌
并排
正在显示
19 个修改的文件
包含
330 行增加
和
141 行删除
+330
-141
Request.js
lib/Channel/Request.js
+28
-3
index.js
lib/Channel/index.js
+87
-7
Room.js
lib/Room.js
+20
-5
Worker.js
lib/Worker.js
+44
-10
UnixStreamSocket.h
worker/include/Channel/UnixStreamSocket.h
+3
-4
Logger.h
worker/include/Logger.h
+10
-30
TCPConnection.h
worker/include/RTC/TCPConnection.h
+1
-1
common.h
worker/include/common.h
+1
-2
TCPConnection.h
worker/include/handles/TCPConnection.h
+1
-1
UnixStreamSocket.h
worker/include/handles/UnixStreamSocket.h
+1
-1
UnixStreamSocket.cpp
worker/src/Channel/UnixStreamSocket.cpp
+115
-59
Logger.cpp
worker/src/Logger.cpp
+2
-0
Peer.cpp
worker/src/RTC/Peer.cpp
+2
-2
TCPConnection.cpp
worker/src/RTC/TCPConnection.cpp
+4
-3
Settings.cpp
worker/src/Settings.cpp
+0
-2
TCPConnection.cpp
worker/src/handles/TCPConnection.cpp
+4
-4
UDPSocket.cpp
worker/src/handles/UDPSocket.cpp
+2
-2
UnixStreamSocket.cpp
worker/src/handles/UnixStreamSocket.cpp
+4
-4
main.cpp
worker/src/main.cpp
+1
-1
没有找到文件。
lib/Channel/Request.js
浏览文件 @
ca8f4364
...
...
@@ -9,9 +9,34 @@ class Request
{
logger
.
debug
(
'constructor() [method:%s]'
,
method
);
this
.
id
=
randomString
({
length
:
8
}).
toLowerCase
();
this
.
method
=
method
;
this
.
data
=
data
||
{};
this
.
_id
=
randomString
({
length
:
8
}).
toLowerCase
();
this
.
_method
=
method
;
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
;
}
}
...
...
lib/Channel/index.js
浏览文件 @
ca8f4364
...
...
@@ -5,6 +5,9 @@ const netstring = require('netstring');
const
logger
=
require
(
'../logger'
)(
'Channel'
);
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
{
constructor
(
socket
)
...
...
@@ -16,8 +19,25 @@ class Channel extends EventEmitter
// Unix Socket instance
this
.
_socket
=
socket
;
// Map of sent requests waiting for a response
this
.
_pendingRequests
=
new
Map
();
this
.
_pendingSent
=
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
)
...
...
@@ -25,13 +45,73 @@ class Channel extends EventEmitter
logger
.
debug
(
'sendRequest() [method:%s]'
,
method
);
let
request
=
new
Request
(
method
,
data
);
let
json
=
JSON
.
stringify
(
request
);
let
ns
=
netstring
.
nsWrite
(
json
);
let
ns
=
netstring
.
nsWrite
(
request
.
serialize
());
let
promise
;
// This may raise if closed or remote side ended
try
{
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
);
}
};
logger
.
debug
(
'nsWriteLength: %s'
,
netstring
.
nsWriteLength
(
Buffer
.
byteLength
(
json
)));
// Add sent stuff to the Map
this
.
_pendingSent
.
set
(
request
.
id
,
sent
);
});
// TODO: This may raise if closed or remote side ended
this
.
_socket
.
write
(
ns
);
return
promise
;
}
}
...
...
lib/Room.js
浏览文件 @
ca8f4364
...
...
@@ -23,20 +23,35 @@ class Room extends EventEmitter
let
data
=
{
foo
:
'lalala'
,
bar
:
1234
foo
:
'lalala'
,
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()'
);
this
.
_status
=
STATUS
.
CLOSED
;
this
.
emit
(
'close'
);
this
.
emit
(
'close'
,
error
);
}
}
...
...
lib/Worker.js
浏览文件 @
ca8f4364
...
...
@@ -10,9 +10,11 @@ const Room = require('./Room');
const
WORKER_BIN_PATH
=
path
.
join
(
__dirname
,
'..'
,
'worker'
,
'bin'
,
'mediasoup-worker'
);
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_LOGGER_FD
=
String
(
LOGGER_FD
);
class
Worker
extends
EventEmitter
{
...
...
@@ -26,7 +28,15 @@ class Worker extends EventEmitter
let
spawnOptions
=
{
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
...
...
@@ -38,17 +48,36 @@ class Worker extends EventEmitter
// Set of Room instances
this
.
_rooms
=
new
Set
();
// Set child process events
this
.
_child
.
stdout
.
on
(
'data'
,
(
buffer
)
=>
// Set worker logger
this
.
_child
.
stdio
[
LOGGER_FD
].
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
)
=>
{
switch
(
line
[
0
])
{
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
}
`
);
}
});
});
this
.
_child
.
stderr
.
on
(
'data'
,
(
buffer
)
=>
{
buffer
.
toString
(
'utf8'
).
split
(
'
\
n'
).
forEach
((
line
)
=>
line
&&
logger
.
error
(
line
));
});
// Set child process events
this
.
_child
.
on
(
'exit'
,
(
code
,
signal
)
=>
{
...
...
@@ -71,8 +100,13 @@ class Worker extends EventEmitter
logger
.
debug
(
'close()'
);
// Kill child
this
.
_child
.
removeAllListeners
(
'exit'
);
this
.
_child
.
removeAllListeners
(
'error'
);
this
.
_child
.
kill
(
'SIGTERM'
);
// Close the Channel instance
this
.
_channel
.
close
();
// Close every Room
this
.
_rooms
.
forEach
(
room
=>
room
.
close
());
...
...
worker/include/Channel/UnixStreamSocket.h
浏览文件 @
ca8f4364
...
...
@@ -20,17 +20,16 @@ namespace Channel
UnixStreamSocket
(
Listener
*
listener
,
int
fd
);
virtual
~
UnixStreamSocket
();
private
:
void
Reset
();
/* Pure virtual methods inherited from ::UnixStreamSocket. */
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
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
// Others:
size_t
msgStart
=
0
;
// Where the latest message starts.
};
}
...
...
worker/include/Logger.h
浏览文件 @
ca8f4364
...
...
@@ -4,9 +4,9 @@
#include "common.h"
#include "Settings.h"
#include <string>
#include <cstdio> // stdout, stderr,
fflush
()
#include <cstdio> // stdout, stderr,
dprintf
()
#include <cstring>
#include <cstdlib> // std::_Exit(), std::abort()
#include <cstdlib> // std::_Exit(), std::abort()
, std::genenv()
#include <uv.h>
/*
...
...
@@ -19,7 +19,6 @@
*
* - MS_TRACE() Shows current file/line/class/function.
* - MS_DEBUG(...)
* - MS_INFO(...)
* - MS_WARN(...)
* - MS_ERROR(...)
* - MS_ABORT(...)
...
...
@@ -51,6 +50,7 @@ public:
public
:
static
std
::
string
id
;
static
int
fd
;
};
/* Inline static methods. */
...
...
@@ -63,6 +63,8 @@ bool Logger::HasDebugLevel()
// NOTE: Each file including Logger.h MUST define its own MS_CLASS macro.
#define _MS_LOG_SEPARATOR_CHAR "\f"
#ifdef MS_DEVEL
#define _MS_LOG_STR "[%s] %s:%d | %s::%s()"
#define _MS_LOG_STR_DESC _MS_LOG_STR " | "
...
...
@@ -74,23 +76,11 @@ bool Logger::HasDebugLevel()
#define _MS_LOG_ARG ("id:" + Logger::id).c_str(), MS_CLASS, __FUNCTION__
#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
#define MS_TRACE() \
do \
{ \
_MS_TO_STDOUT(
); \
dprintf(Logger::fd, "D" _MS_LOG_STR _MS_LOG_SEPARATOR_CHAR, _MS_LOG_ARG
); \
} \
while (0)
#else
...
...
@@ -102,17 +92,7 @@ bool Logger::HasDebugLevel()
{ \
if (MS_LOG_LEVEL_DEBUG == MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC(desc, ##__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__); \
dprintf(Logger::fd, "D" _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR, _MS_LOG_ARG, ##__VA_ARGS__); \
} \
} \
while (0)
...
...
@@ -122,7 +102,7 @@ bool Logger::HasDebugLevel()
{ \
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)
...
...
@@ -130,14 +110,14 @@ bool Logger::HasDebugLevel()
#define MS_ERROR(desc, ...) \
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)
#define MS_EXIT_SUCCESS(desc, ...) \
do \
{ \
MS_
INFO
("SUCCESS EXIT | " desc, ##__VA_ARGS__); \
MS_
DEBUG
("SUCCESS EXIT | " desc, ##__VA_ARGS__); \
std::_Exit(EXIT_SUCCESS); \
} \
while (0)
...
...
worker/include/RTC/TCPConnection.h
浏览文件 @
ca8f4364
...
...
@@ -26,7 +26,7 @@ namespace RTC
/* Pure virtual methods inherited from ::TCPConnection. */
public
:
virtual
void
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
userOnTCPConnectionRead
()
override
;
private
:
// Passed by argument:
...
...
worker/include/common.h
浏览文件 @
ca8f4364
...
...
@@ -10,8 +10,7 @@
#define MS_APP_NAME "mediasoup"
#define MS_PROCESS_NAME "mediasoup-worker"
#define MS_LOG_LEVEL_DEBUG 3
#define MS_LOG_LEVEL_INFO 2
#define MS_LOG_LEVEL_DEBUG 2
#define MS_LOG_LEVEL_WARN 1
#define MS_LOG_LEVEL_ERROR 0
...
...
worker/include/handles/TCPConnection.h
浏览文件 @
ca8f4364
...
...
@@ -56,7 +56,7 @@ public:
/* Pure virtual methods that must be implemented by the subclass. */
protected
:
virtual
void
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
userOnTCPConnectionRead
()
=
0
;
private
:
// Allocated by this:
...
...
worker/include/handles/UnixStreamSocket.h
浏览文件 @
ca8f4364
...
...
@@ -37,7 +37,7 @@ public:
/* Pure virtual methods that must be implemented by the subclass. */
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
;
private
:
...
...
worker/src/Channel/UnixStreamSocket.cpp
浏览文件 @
ca8f4364
...
...
@@ -4,7 +4,8 @@
#include "Logger.h"
#include <json/json.h>
#include <netstring.h>
#include <cstring> // std::memmove()
#
#define MESSAGE_MAX_SIZE 65536 // TODO: set proper buffer size
namespace
Channel
...
...
@@ -23,81 +24,136 @@ namespace Channel
MS_TRACE
();
}
void
UnixStreamSocket
::
Reset
()
void
UnixStreamSocket
::
userOnUnixStreamRead
()
{
MS_TRACE
();
// reset parsing stuff, dataLen, etc
}
void
UnixStreamSocket
::
userOnUnixStreamRead
(
const
MS_BYTE
*
data
,
size_t
len
)
{
MS_TRACE
();
std
::
string
kk
((
const
char
*
)
data
,
len
);
MS_WARN
(
"---------- readed data: %s"
,
kk
.
c_str
());
this
->
bufferDataLen
=
0
;
// Be ready to parse more than a single message in a single TCP chunk.
while
(
true
)
{
size_t
read_len
=
this
->
bufferDataLen
-
this
->
msgStart
;
char
*
json_start
=
nullptr
;
size_t
json_len
;
int
ns_ret
=
netstring_read
((
char
*
)(
this
->
buffer
+
this
->
msgStart
),
read_len
,
&
json_start
,
&
json_len
);
char
*
ns_start
=
nullptr
;
size_t
ns_length
;
int
ns_ret
=
netstring_read
((
char
*
)
data
,
len
,
&
ns_start
,
&
ns_length
);
std
::
string
kk1
((
const
char
*
)(
this
->
buffer
+
this
->
msgStart
),
read_len
);
MS_WARN
(
"* loop data: <%s>"
,
kk1
.
c_str
());
if
(
ns_ret
!=
0
)
{
switch
(
ns_ret
)
if
(
ns_ret
!=
0
)
{
case
NETSTRING_ERROR_TOO_SHORT
:
MS_DEBUG
(
"received netstring is too short, waiting for more data"
);
return
;
case
NETSTRING_ERROR_TOO_LONG
:
MS_ERROR
(
"NETSTRING_ERROR_TOO_LONG"
);
break
;
case
NETSTRING_ERROR_NO_COLON
:
MS_ERROR
(
"NETSTRING_ERROR_NO_COLON"
);
break
;
case
NETSTRING_ERROR_NO_COMMA
:
MS_ERROR
(
"NETSTRING_ERROR_NO_COMMA"
);
break
;
case
NETSTRING_ERROR_LEADING_ZERO
:
MS_ERROR
(
"NETSTRING_ERROR_LEADING_ZERO"
);
break
;
case
NETSTRING_ERROR_NO_LENGTH
:
MS_ERROR
(
"NETSTRING_ERROR_NO_LENGTH"
);
break
;
switch
(
ns_ret
)
{
case
NETSTRING_ERROR_TOO_SHORT
:
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
;
case
NETSTRING_ERROR_TOO_LONG
:
MS_ERROR
(
"NETSTRING_ERROR_TOO_LONG"
);
break
;
case
NETSTRING_ERROR_NO_COLON
:
MS_ERROR
(
"NETSTRING_ERROR_NO_COLON"
);
break
;
case
NETSTRING_ERROR_NO_COMMA
:
MS_ERROR
(
"NETSTRING_ERROR_NO_COMMA"
);
break
;
case
NETSTRING_ERROR_LEADING_ZERO
:
MS_ERROR
(
"NETSTRING_ERROR_LEADING_ZERO"
);
break
;
case
NETSTRING_ERROR_NO_LENGTH
:
MS_ERROR
(
"NETSTRING_ERROR_NO_LENGTH"
);
break
;
}
// Error, so reset and exit the parsing loop.
this
->
msgStart
=
0
;
this
->
bufferDataLen
=
0
;
return
;
}
Reset
();
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
::
Reader
reader
;
if
(
reader
.
parse
((
const
char
*
)
json_start
,
(
const
char
*
)
json_start
+
json_len
,
json
))
{
MS_DEBUG
(
"jsoncpp: IT IS VALID JSON:
\n
%s"
,
json
.
toStyledString
().
c_str
());
Write
(
"VALID JSON MAN !!!!:"
);
Write
(
json
.
toStyledString
());
Json
::
Value
json
;
Json
::
Reader
reader
;
if
(
reader
.
parse
((
const
char
*
)
ns_start
,
(
const
char
*
)
ns_start
+
ns_length
,
json
))
{
MS_INFO
(
"jsoncpp: IT IS VALID JSON:
\n\n
%s
\n
"
,
json
.
toStyledString
().
c_str
());
// TODO: process it
}
else
{
MS_ERROR
(
"jsoncpp: INVALID JSON !!!!"
);
// 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");
MS_ASSERT
(
1
!=
2
,
"--------- INVALID JSON !!!"
);
}
// if (json["method"].isString())
// MS_DEBUG("jsoncpp: method is a string");
// 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"
);
// if (!json.isMember("kk"))
// MS_DEBUG("jsoncpp: kk is not member");
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 (json["parent"]["foo"]["bar"].isNull())
// MS_DEBUG("jsoncpp: parent.foo.bar is null");
}
else
{
MS_ERROR
(
"jsoncpp: INVALID JSON !!!!"
);
// 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
;
}
}
}
...
...
worker/src/Logger.cpp
浏览文件 @
ca8f4364
...
...
@@ -5,12 +5,14 @@
/* Static variables. */
std
::
string
Logger
::
id
;
int
Logger
::
fd
;
/* Static methods. */
void
Logger
::
Init
(
const
std
::
string
id
)
{
Logger
::
id
=
id
;
Logger
::
fd
=
std
::
stoi
(
std
::
getenv
(
"MEDIASOUP_LOGGER_FD"
));
MS_TRACE
();
}
worker/src/RTC/Peer.cpp
浏览文件 @
ca8f4364
...
...
@@ -36,7 +36,7 @@ namespace RTC
{
RTC
::
UDPSocket
*
socket
=
RTC
::
UDPSocket
::
New
(
AF_INET
);
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
)
{
...
...
@@ -47,7 +47,7 @@ namespace RTC
{
RTC
::
TCPServer
*
server
=
RTC
::
TCPServer
::
New
(
AF_INET
);
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
)
{
...
...
worker/src/RTC/TCPConnection.cpp
浏览文件 @
ca8f4364
...
...
@@ -25,12 +25,13 @@ namespace RTC
MS_TRACE
();
}
void
TCPConnection
::
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
void
TCPConnection
::
userOnTCPConnectionRead
()
{
MS_TRACE
();
MS_DEBUG
(
"%zu bytes received [local: %s : %u | remote: %s : %u]"
,
len
,
GetLocalIP
().
c_str
(),
(
unsigned
int
)
GetLocalPort
(),
GetPeerIP
().
c_str
(),
(
unsigned
int
)
GetPeerPort
());
MS_DEBUG
(
"data received [local: %s : %u | remote: %s : %u]"
,
GetLocalIP
().
c_str
(),
(
unsigned
int
)
GetLocalPort
(),
GetPeerIP
().
c_str
(),
(
unsigned
int
)
GetPeerPort
());
/*
* Framing RFC 4571
...
...
worker/src/Settings.cpp
浏览文件 @
ca8f4364
...
...
@@ -27,14 +27,12 @@ struct Settings::Configuration Settings::configuration;
std
::
map
<
std
::
string
,
unsigned
int
>
Settings
::
string2LogLevel
=
{
{
"debug"
,
MS_LOG_LEVEL_DEBUG
},
{
"info"
,
MS_LOG_LEVEL_INFO
},
{
"warn"
,
MS_LOG_LEVEL_WARN
},
{
"error"
,
MS_LOG_LEVEL_ERROR
}
};
std
::
map
<
unsigned
int
,
std
::
string
>
Settings
::
logLevel2String
=
{
{
MS_LOG_LEVEL_DEBUG
,
"debug"
},
{
MS_LOG_LEVEL_INFO
,
"info"
},
{
MS_LOG_LEVEL_WARN
,
"warn"
},
{
MS_LOG_LEVEL_ERROR
,
"error"
}
};
...
...
worker/src/handles/TCPConnection.cpp
浏览文件 @
ca8f4364
...
...
@@ -352,7 +352,7 @@ void TCPConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
this
->
bufferDataLen
+=
(
size_t
)
nread
;
// Notify the subclass.
userOnTCPConnectionRead
(
(
MS_BYTE
*
)
buf
->
base
,
nread
);
userOnTCPConnectionRead
();
}
// Client disconneted.
else
if
(
nread
==
UV_EOF
||
nread
==
UV_ECONNRESET
)
...
...
@@ -366,7 +366,7 @@ void TCPConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
// Some error.
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
;
// Close server side of the connection.
...
...
@@ -389,7 +389,7 @@ void TCPConnection::onUvWriteError(int error)
}
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
;
}
...
...
@@ -406,7 +406,7 @@ void TCPConnection::onUvShutdown(uv_shutdown_t* req, int status)
if
(
status
==
UV_EPIPE
||
status
==
UV_ENOTCONN
||
status
==
UV_ECANCELED
)
MS_DEBUG
(
"shutdown error: %s"
,
uv_strerror
(
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.
uv_close
((
uv_handle_t
*
)
this
->
uvHandle
,
(
uv_close_cb
)
on_close
);
...
...
worker/src/handles/UDPSocket.cpp
浏览文件 @
ca8f4364
...
...
@@ -344,7 +344,7 @@ void UDPSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad
// Some error.
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)
if
(
this
->
isClosing
)
return
;
MS_
INFO
(
"send error: %s"
,
uv_strerror
(
error
));
MS_
DEBUG
(
"send error: %s"
,
uv_strerror
(
error
));
}
inline
...
...
worker/src/handles/UnixStreamSocket.cpp
浏览文件 @
ca8f4364
...
...
@@ -240,7 +240,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf)
this
->
bufferDataLen
+=
(
size_t
)
nread
;
// Notify the subclass.
userOnUnixStreamRead
(
(
MS_BYTE
*
)
buf
->
base
,
nread
);
userOnUnixStreamRead
();
}
// Peer disconneted.
else
if
(
nread
==
UV_EOF
||
nread
==
UV_ECONNRESET
)
...
...
@@ -254,7 +254,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf)
// Some error.
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
;
// Close the socket.
...
...
@@ -277,7 +277,7 @@ void UnixStreamSocket::onUvWriteError(int error)
}
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
;
}
...
...
@@ -294,7 +294,7 @@ void UnixStreamSocket::onUvShutdown(uv_shutdown_t* req, int status)
if
(
status
==
UV_EPIPE
||
status
==
UV_ENOTCONN
||
status
==
UV_ECANCELED
)
MS_DEBUG
(
"shutdown error: %s"
,
uv_strerror
(
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.
uv_close
((
uv_handle_t
*
)
this
->
uvHandle
,
(
uv_close_cb
)
on_close
);
...
...
worker/src/main.cpp
浏览文件 @
ca8f4364
...
...
@@ -53,7 +53,7 @@ int main(int argc, char* argv[], char** envp)
// Print configuration.
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)
MS_DEBUG
(
"detected Little-Endian CPU"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论