Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
5c2208d5
提交
5c2208d5
authored
8月 03, 2019
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix TCP leak (#325).
上级
2f434d7e
显示空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
67 行增加
和
42 行删除
+67
-42
TcpConnection.hpp
worker/include/RTC/TcpConnection.hpp
+1
-0
TcpServer.hpp
worker/include/RTC/TcpServer.hpp
+3
-3
WebRtcTransport.hpp
worker/include/RTC/WebRtcTransport.hpp
+1
-2
TcpConnection.hpp
worker/include/handles/TcpConnection.hpp
+2
-1
TcpServer.hpp
worker/include/handles/TcpServer.hpp
+3
-3
TcpConnection.cpp
worker/src/RTC/TcpConnection.cpp
+7
-2
TcpServer.cpp
worker/src/RTC/TcpServer.cpp
+11
-7
WebRtcTransport.cpp
worker/src/RTC/WebRtcTransport.cpp
+1
-2
TcpConnection.cpp
worker/src/handles/TcpConnection.cpp
+24
-3
TcpServer.cpp
worker/src/handles/TcpServer.cpp
+14
-19
没有找到文件。
worker/include/RTC/TcpConnection.hpp
浏览文件 @
5c2208d5
...
@@ -18,6 +18,7 @@ namespace RTC
...
@@ -18,6 +18,7 @@ namespace RTC
public
:
public
:
TcpConnection
(
Listener
*
listener
,
size_t
bufferSize
);
TcpConnection
(
Listener
*
listener
,
size_t
bufferSize
);
~
TcpConnection
()
override
;
public
:
public
:
void
Send
(
const
uint8_t
*
data
,
size_t
len
);
void
Send
(
const
uint8_t
*
data
,
size_t
len
);
...
...
worker/include/RTC/TcpServer.hpp
浏览文件 @
5c2208d5
...
@@ -16,7 +16,7 @@ namespace RTC
...
@@ -16,7 +16,7 @@ namespace RTC
{
{
public
:
public
:
virtual
void
OnRtcTcpConnectionClosed
(
virtual
void
OnRtcTcpConnectionClosed
(
RTC
::
TcpServer
*
tcpServer
,
RTC
::
TcpConnection
*
connection
,
bool
isClosedByPeer
)
=
0
;
RTC
::
TcpServer
*
tcpServer
,
RTC
::
TcpConnection
*
connection
)
=
0
;
};
};
public
:
public
:
...
@@ -26,8 +26,8 @@ namespace RTC
...
@@ -26,8 +26,8 @@ namespace RTC
/* Pure virtual methods inherited from ::TcpServer. */
/* Pure virtual methods inherited from ::TcpServer. */
public
:
public
:
void
UserOnTcpConnectionAlloc
(
::
TcpConnection
**
connection
)
override
;
void
UserOnTcpConnectionAlloc
(
::
TcpConnection
**
connection
)
override
;
void
UserOnNewTcpConnection
(
::
TcpConnection
*
connection
)
override
;
bool
UserOnNewTcpConnection
(
::
TcpConnection
*
connection
)
override
;
void
UserOnTcpConnectionClosed
(
::
TcpConnection
*
connection
,
bool
isClosedByPeer
)
override
;
void
UserOnTcpConnectionClosed
(
::
TcpConnection
*
connection
)
override
;
private
:
private
:
// Passed by argument.
// Passed by argument.
...
...
worker/include/RTC/WebRtcTransport.hpp
浏览文件 @
5c2208d5
...
@@ -77,8 +77,7 @@ namespace RTC
...
@@ -77,8 +77,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::TcpServer::Listener. */
/* Pure virtual methods inherited from RTC::TcpServer::Listener. */
public
:
public
:
void
OnRtcTcpConnectionClosed
(
void
OnRtcTcpConnectionClosed
(
RTC
::
TcpServer
*
tcpServer
,
RTC
::
TcpConnection
*
connection
)
override
;
RTC
::
TcpServer
*
tcpServer
,
RTC
::
TcpConnection
*
connection
,
bool
isClosedByPeer
)
override
;
/* Pure virtual methods inherited from RTC::TcpConnection::Listener. */
/* Pure virtual methods inherited from RTC::TcpConnection::Listener. */
public
:
public
:
...
...
worker/include/handles/TcpConnection.hpp
浏览文件 @
5c2208d5
...
@@ -18,7 +18,7 @@ public:
...
@@ -18,7 +18,7 @@ public:
virtual
~
Listener
()
=
default
;
virtual
~
Listener
()
=
default
;
public
:
public
:
virtual
void
OnTcpConnectionClosed
(
TcpConnection
*
connection
,
bool
isClosedByPeer
)
=
0
;
virtual
void
OnTcpConnectionClosed
(
TcpConnection
*
connection
)
=
0
;
};
};
public
:
public
:
...
@@ -52,6 +52,7 @@ public:
...
@@ -52,6 +52,7 @@ public:
void
Write
(
const
uint8_t
*
data
,
size_t
len
);
void
Write
(
const
uint8_t
*
data
,
size_t
len
);
void
Write
(
const
uint8_t
*
data1
,
size_t
len1
,
const
uint8_t
*
data2
,
size_t
len2
);
void
Write
(
const
uint8_t
*
data1
,
size_t
len1
,
const
uint8_t
*
data2
,
size_t
len2
);
void
Write
(
const
std
::
string
&
data
);
void
Write
(
const
std
::
string
&
data
);
void
ErrorReceiving
();
const
struct
sockaddr
*
GetLocalAddress
()
const
;
const
struct
sockaddr
*
GetLocalAddress
()
const
;
int
GetLocalFamily
()
const
;
int
GetLocalFamily
()
const
;
const
std
::
string
&
GetLocalIp
()
const
;
const
std
::
string
&
GetLocalIp
()
const
;
...
...
worker/include/handles/TcpServer.hpp
浏览文件 @
5c2208d5
...
@@ -31,8 +31,8 @@ private:
...
@@ -31,8 +31,8 @@ private:
/* Pure virtual methods that must be implemented by the subclass. */
/* Pure virtual methods that must be implemented by the subclass. */
protected
:
protected
:
virtual
void
UserOnTcpConnectionAlloc
(
TcpConnection
**
connection
)
=
0
;
virtual
void
UserOnTcpConnectionAlloc
(
TcpConnection
**
connection
)
=
0
;
virtual
void
UserOnNewTcpConnection
(
TcpConnection
*
connection
)
=
0
;
virtual
bool
UserOnNewTcpConnection
(
TcpConnection
*
connection
)
=
0
;
virtual
void
UserOnTcpConnectionClosed
(
TcpConnection
*
connection
,
bool
isClosedByPeer
)
=
0
;
virtual
void
UserOnTcpConnectionClosed
(
TcpConnection
*
connection
)
=
0
;
/* Callbacks fired by UV events. */
/* Callbacks fired by UV events. */
public
:
public
:
...
@@ -40,7 +40,7 @@ public:
...
@@ -40,7 +40,7 @@ public:
/* Methods inherited from TcpConnection::Listener. */
/* Methods inherited from TcpConnection::Listener. */
public
:
public
:
void
OnTcpConnectionClosed
(
TcpConnection
*
connection
,
bool
isClosedByPeer
)
override
;
void
OnTcpConnectionClosed
(
TcpConnection
*
connection
)
override
;
protected
:
protected
:
struct
sockaddr_storage
localAddr
;
struct
sockaddr_storage
localAddr
;
...
...
worker/src/RTC/TcpConnection.cpp
浏览文件 @
5c2208d5
...
@@ -21,6 +21,11 @@ namespace RTC
...
@@ -21,6 +21,11 @@ namespace RTC
MS_TRACE
();
MS_TRACE
();
}
}
TcpConnection
::~
TcpConnection
()
{
MS_TRACE
();
}
void
TcpConnection
::
UserOnTcpConnectionRead
()
void
TcpConnection
::
UserOnTcpConnectionRead
()
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -135,7 +140,7 @@ namespace RTC
...
@@ -135,7 +140,7 @@ namespace RTC
"connection"
);
"connection"
);
// Close the socket.
// Close the socket.
Close
();
::
TcpConnection
::
ErrorReceiving
();
}
}
}
}
// The buffer is not full.
// The buffer is not full.
...
@@ -161,6 +166,6 @@ namespace RTC
...
@@ -161,6 +166,6 @@ namespace RTC
uint8_t
frameLen
[
2
];
uint8_t
frameLen
[
2
];
Utils
::
Byte
::
Set2Bytes
(
frameLen
,
0
,
len
);
Utils
::
Byte
::
Set2Bytes
(
frameLen
,
0
,
len
);
Write
(
frameLen
,
2
,
data
,
len
);
::
TcpConnection
::
Write
(
frameLen
,
2
,
data
,
len
);
}
}
}
// namespace RTC
}
// namespace RTC
worker/src/RTC/TcpServer.cpp
浏览文件 @
5c2208d5
...
@@ -37,20 +37,24 @@ namespace RTC
...
@@ -37,20 +37,24 @@ namespace RTC
*
connection
=
new
RTC
::
TcpConnection
(
this
->
connListener
,
65536
);
*
connection
=
new
RTC
::
TcpConnection
(
this
->
connListener
,
65536
);
}
}
void
TcpServer
::
UserOnNewTcpConnection
(
::
TcpConnection
*
connection
)
bool
TcpServer
::
UserOnNewTcpConnection
(
::
TcpConnection
*
connection
)
{
{
MS_TRACE
();
MS_TRACE
();
// Allow just MaxTcpConnectionsPerServer.
if
(
GetNumConnections
()
>=
MaxTcpConnectionsPerServer
)
if
(
GetNumConnections
()
>
MaxTcpConnectionsPerServer
)
{
delete
connection
;
MS_ERROR
(
"cannot handle more than %zu connections"
,
MaxTcpConnectionsPerServer
);
return
false
;
}
return
true
;
}
}
void
TcpServer
::
UserOnTcpConnectionClosed
(
::
TcpConnection
*
connection
,
bool
isClosedByPeer
)
void
TcpServer
::
UserOnTcpConnectionClosed
(
::
TcpConnection
*
connection
)
{
{
MS_TRACE
();
MS_TRACE
();
this
->
listener
->
OnRtcTcpConnectionClosed
(
this
->
listener
->
OnRtcTcpConnectionClosed
(
this
,
static_cast
<
RTC
::
TcpConnection
*>
(
connection
));
this
,
static_cast
<
RTC
::
TcpConnection
*>
(
connection
),
isClosedByPeer
);
}
}
}
// namespace RTC
}
// namespace RTC
worker/src/RTC/WebRtcTransport.cpp
浏览文件 @
5c2208d5
...
@@ -1408,13 +1408,12 @@ namespace RTC
...
@@ -1408,13 +1408,12 @@ namespace RTC
}
}
inline
void
WebRtcTransport
::
OnRtcTcpConnectionClosed
(
inline
void
WebRtcTransport
::
OnRtcTcpConnectionClosed
(
RTC
::
TcpServer
*
/*tcpServer*/
,
RTC
::
TcpConnection
*
connection
,
bool
isClosedByPeer
)
RTC
::
TcpServer
*
/*tcpServer*/
,
RTC
::
TcpConnection
*
connection
)
{
{
MS_TRACE
();
MS_TRACE
();
RTC
::
TransportTuple
tuple
(
connection
);
RTC
::
TransportTuple
tuple
(
connection
);
if
(
isClosedByPeer
)
this
->
iceServer
->
RemoveTuple
(
&
tuple
);
this
->
iceServer
->
RemoveTuple
(
&
tuple
);
}
}
...
...
worker/src/handles/TcpConnection.cpp
浏览文件 @
5c2208d5
...
@@ -124,9 +124,6 @@ void TcpConnection::Close()
...
@@ -124,9 +124,6 @@ void TcpConnection::Close()
{
{
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_close_cb
>
(
onClose
));
uv_close
(
reinterpret_cast
<
uv_handle_t
*>
(
this
->
uvHandle
),
static_cast
<
uv_close_cb
>
(
onClose
));
}
}
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
,
this
->
isClosedByPeer
);
}
}
void
TcpConnection
::
Dump
()
const
void
TcpConnection
::
Dump
()
const
...
@@ -221,6 +218,9 @@ void TcpConnection::Write(const uint8_t* data, size_t len)
...
@@ -221,6 +218,9 @@ void TcpConnection::Write(const uint8_t* data, size_t len)
Close
();
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
return
;
return
;
}
}
...
@@ -288,6 +288,9 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
...
@@ -288,6 +288,9 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
Close
();
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
return
;
return
;
}
}
...
@@ -327,6 +330,15 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
...
@@ -327,6 +330,15 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
MS_ABORT
(
"uv_write() failed: %s"
,
uv_strerror
(
err
));
MS_ABORT
(
"uv_write() failed: %s"
,
uv_strerror
(
err
));
}
}
void
TcpConnection
::
ErrorReceiving
()
{
MS_ERROR
();
Close
();
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
bool
TcpConnection
::
SetPeerAddress
()
bool
TcpConnection
::
SetPeerAddress
()
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -406,6 +418,9 @@ inline void TcpConnection::OnUvRead(ssize_t nread, const uv_buf_t* /*buf*/)
...
@@ -406,6 +418,9 @@ inline void TcpConnection::OnUvRead(ssize_t nread, const uv_buf_t* /*buf*/)
// Close server side of the connection.
// Close server side of the connection.
Close
();
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
}
// Some error.
// Some error.
else
else
...
@@ -416,6 +431,9 @@ inline void TcpConnection::OnUvRead(ssize_t nread, const uv_buf_t* /*buf*/)
...
@@ -416,6 +431,9 @@ inline void TcpConnection::OnUvRead(ssize_t nread, const uv_buf_t* /*buf*/)
// Close server side of the connection.
// Close server side of the connection.
Close
();
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
}
}
}
...
@@ -432,4 +450,7 @@ inline void TcpConnection::OnUvWriteError(int error)
...
@@ -432,4 +450,7 @@ inline void TcpConnection::OnUvWriteError(int error)
MS_WARN_DEV
(
"write error, closing the connection: %s"
,
uv_strerror
(
error
));
MS_WARN_DEV
(
"write error, closing the connection: %s"
,
uv_strerror
(
error
));
Close
();
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
}
worker/src/handles/TcpServer.cpp
浏览文件 @
5c2208d5
...
@@ -77,11 +77,8 @@ void TcpServer::Close()
...
@@ -77,11 +77,8 @@ void TcpServer::Close()
MS_DEBUG_DEV
(
"closing %zu active connections"
,
this
->
connections
.
size
());
MS_DEBUG_DEV
(
"closing %zu active connections"
,
this
->
connections
.
size
());
for
(
auto
it
=
this
->
connections
.
begin
();
it
!=
this
->
connections
.
end
();
)
for
(
auto
*
connection
:
this
->
connections
)
{
{
auto
*
connection
=
*
it
;
it
=
this
->
connections
.
erase
(
it
);
delete
connection
;
delete
connection
;
}
}
...
@@ -166,38 +163,36 @@ inline void TcpServer::OnUvConnection(int status)
...
@@ -166,38 +163,36 @@ inline void TcpServer::OnUvConnection(int status)
if
(
err
!=
0
)
if
(
err
!=
0
)
MS_ABORT
(
"uv_accept() failed: %s"
,
uv_strerror
(
err
));
MS_ABORT
(
"uv_accept() failed: %s"
,
uv_strerror
(
err
));
// Insert the TcpConnection in the set.
this
->
connections
.
insert
(
connection
);
// Start receiving data.
// Start receiving data.
try
try
{
{
// NOTE: This may throw.
connection
->
Start
();
connection
->
Start
();
// Notify the subclass.
UserOnNewTcpConnection
(
connection
);
}
}
catch
(
const
MediaSoupError
&
error
)
catch
(
const
MediaSoupError
&
error
)
{
{
MS_ERROR
(
"cannot start the TCP connection, closing the connection: %s"
,
error
.
what
());
delete
connection
;
delete
connection
;
}
}
// Notify the subclass and delete the connection if not accepted by the subclass.
if
(
UserOnNewTcpConnection
(
connection
))
this
->
connections
.
insert
(
connection
);
else
delete
connection
;
}
}
inline
void
TcpServer
::
OnTcpConnectionClosed
(
TcpConnection
*
connection
,
bool
isClosedByPeer
)
inline
void
TcpServer
::
OnTcpConnectionClosed
(
TcpConnection
*
connection
)
{
{
MS_TRACE
();
MS_TRACE
();
MS_DEBUG_DEV
(
"TCP connection closed"
);
MS_DEBUG_DEV
(
"TCP connection closed"
);
// Remove the TcpConnection from the set.
// Remove the TcpConnection from the set.
size_t
numErased
=
this
->
connections
.
erase
(
connection
);
this
->
connections
.
erase
(
connection
);
// If the closed connection was not present in the set, do nothing else.
if
(
numErased
==
0
)
return
;
// Notify the subclass.
// Notify the subclass.
UserOnTcpConnectionClosed
(
connection
,
isClosedByPeer
);
UserOnTcpConnectionClosed
(
connection
);
// Delete it.
delete
connection
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论