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 个修改的文件
包含
69 行增加
和
44 行删除
+69
-44
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
+4
-4
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
+2
-3
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
public
:
TcpConnection
(
Listener
*
listener
,
size_t
bufferSize
);
~
TcpConnection
()
override
;
public
:
void
Send
(
const
uint8_t
*
data
,
size_t
len
);
...
...
worker/include/RTC/TcpServer.hpp
浏览文件 @
5c2208d5
...
...
@@ -16,7 +16,7 @@ namespace RTC
{
public
:
virtual
void
OnRtcTcpConnectionClosed
(
RTC
::
TcpServer
*
tcpServer
,
RTC
::
TcpConnection
*
connection
,
bool
isClosedByPeer
)
=
0
;
RTC
::
TcpServer
*
tcpServer
,
RTC
::
TcpConnection
*
connection
)
=
0
;
};
public
:
...
...
@@ -26,8 +26,8 @@ namespace RTC
/* Pure virtual methods inherited from ::TcpServer. */
public
:
void
UserOnTcpConnectionAlloc
(
::
TcpConnection
**
connection
)
override
;
void
UserOnNewTcpConnection
(
::
TcpConnection
*
connection
)
override
;
void
UserOnTcpConnectionClosed
(
::
TcpConnection
*
connection
,
bool
isClosedByPeer
)
override
;
bool
UserOnNewTcpConnection
(
::
TcpConnection
*
connection
)
override
;
void
UserOnTcpConnectionClosed
(
::
TcpConnection
*
connection
)
override
;
private
:
// Passed by argument.
...
...
worker/include/RTC/WebRtcTransport.hpp
浏览文件 @
5c2208d5
...
...
@@ -77,8 +77,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::TcpServer::Listener. */
public
:
void
OnRtcTcpConnectionClosed
(
RTC
::
TcpServer
*
tcpServer
,
RTC
::
TcpConnection
*
connection
,
bool
isClosedByPeer
)
override
;
void
OnRtcTcpConnectionClosed
(
RTC
::
TcpServer
*
tcpServer
,
RTC
::
TcpConnection
*
connection
)
override
;
/* Pure virtual methods inherited from RTC::TcpConnection::Listener. */
public
:
...
...
worker/include/handles/TcpConnection.hpp
浏览文件 @
5c2208d5
...
...
@@ -18,7 +18,7 @@ public:
virtual
~
Listener
()
=
default
;
public
:
virtual
void
OnTcpConnectionClosed
(
TcpConnection
*
connection
,
bool
isClosedByPeer
)
=
0
;
virtual
void
OnTcpConnectionClosed
(
TcpConnection
*
connection
)
=
0
;
};
public
:
...
...
@@ -52,6 +52,7 @@ public:
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
std
::
string
&
data
);
void
ErrorReceiving
();
const
struct
sockaddr
*
GetLocalAddress
()
const
;
int
GetLocalFamily
()
const
;
const
std
::
string
&
GetLocalIp
()
const
;
...
...
worker/include/handles/TcpServer.hpp
浏览文件 @
5c2208d5
...
...
@@ -30,9 +30,9 @@ private:
/* Pure virtual methods that must be implemented by the subclass. */
protected
:
virtual
void
UserOnTcpConnectionAlloc
(
TcpConnection
**
connection
)
=
0
;
virtual
void
UserOnNewTcpConnection
(
TcpConnection
*
connection
)
=
0
;
virtual
void
UserOnTcpConnectionClosed
(
TcpConnection
*
connection
,
bool
isClosedByPeer
)
=
0
;
virtual
void
UserOnTcpConnectionAlloc
(
TcpConnection
**
connection
)
=
0
;
virtual
bool
UserOnNewTcpConnection
(
TcpConnection
*
connection
)
=
0
;
virtual
void
UserOnTcpConnectionClosed
(
TcpConnection
*
connection
)
=
0
;
/* Callbacks fired by UV events. */
public
:
...
...
@@ -40,7 +40,7 @@ public:
/* Methods inherited from TcpConnection::Listener. */
public
:
void
OnTcpConnectionClosed
(
TcpConnection
*
connection
,
bool
isClosedByPeer
)
override
;
void
OnTcpConnectionClosed
(
TcpConnection
*
connection
)
override
;
protected
:
struct
sockaddr_storage
localAddr
;
...
...
worker/src/RTC/TcpConnection.cpp
浏览文件 @
5c2208d5
...
...
@@ -21,6 +21,11 @@ namespace RTC
MS_TRACE
();
}
TcpConnection
::~
TcpConnection
()
{
MS_TRACE
();
}
void
TcpConnection
::
UserOnTcpConnectionRead
()
{
MS_TRACE
();
...
...
@@ -135,7 +140,7 @@ namespace RTC
"connection"
);
// Close the socket.
Close
();
::
TcpConnection
::
ErrorReceiving
();
}
}
// The buffer is not full.
...
...
@@ -161,6 +166,6 @@ namespace RTC
uint8_t
frameLen
[
2
];
Utils
::
Byte
::
Set2Bytes
(
frameLen
,
0
,
len
);
Write
(
frameLen
,
2
,
data
,
len
);
::
TcpConnection
::
Write
(
frameLen
,
2
,
data
,
len
);
}
}
// namespace RTC
worker/src/RTC/TcpServer.cpp
浏览文件 @
5c2208d5
...
...
@@ -37,20 +37,24 @@ namespace RTC
*
connection
=
new
RTC
::
TcpConnection
(
this
->
connListener
,
65536
);
}
void
TcpServer
::
UserOnNewTcpConnection
(
::
TcpConnection
*
connection
)
bool
TcpServer
::
UserOnNewTcpConnection
(
::
TcpConnection
*
connection
)
{
MS_TRACE
();
// Allow just MaxTcpConnectionsPerServer.
if
(
GetNumConnections
()
>
MaxTcpConnectionsPerServer
)
delete
connection
;
if
(
GetNumConnections
()
>=
MaxTcpConnectionsPerServer
)
{
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
();
this
->
listener
->
OnRtcTcpConnectionClosed
(
this
,
static_cast
<
RTC
::
TcpConnection
*>
(
connection
),
isClosedByPeer
);
this
->
listener
->
OnRtcTcpConnectionClosed
(
this
,
static_cast
<
RTC
::
TcpConnection
*>
(
connection
));
}
}
// namespace RTC
worker/src/RTC/WebRtcTransport.cpp
浏览文件 @
5c2208d5
...
...
@@ -1408,14 +1408,13 @@ namespace RTC
}
inline
void
WebRtcTransport
::
OnRtcTcpConnectionClosed
(
RTC
::
TcpServer
*
/*tcpServer*/
,
RTC
::
TcpConnection
*
connection
,
bool
isClosedByPeer
)
RTC
::
TcpServer
*
/*tcpServer*/
,
RTC
::
TcpConnection
*
connection
)
{
MS_TRACE
();
RTC
::
TransportTuple
tuple
(
connection
);
if
(
isClosedByPeer
)
this
->
iceServer
->
RemoveTuple
(
&
tuple
);
this
->
iceServer
->
RemoveTuple
(
&
tuple
);
}
inline
void
WebRtcTransport
::
OnTcpConnectionPacketReceived
(
...
...
worker/src/handles/TcpConnection.cpp
浏览文件 @
5c2208d5
...
...
@@ -124,9 +124,6 @@ void TcpConnection::Close()
{
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
...
...
@@ -221,6 +218,9 @@ void TcpConnection::Write(const uint8_t* data, size_t len)
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
return
;
}
...
...
@@ -288,6 +288,9 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
return
;
}
...
...
@@ -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
));
}
void
TcpConnection
::
ErrorReceiving
()
{
MS_ERROR
();
Close
();
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
bool
TcpConnection
::
SetPeerAddress
()
{
MS_TRACE
();
...
...
@@ -406,6 +418,9 @@ inline void TcpConnection::OnUvRead(ssize_t nread, const uv_buf_t* /*buf*/)
// Close server side of the connection.
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
// Some error.
else
...
...
@@ -416,6 +431,9 @@ inline void TcpConnection::OnUvRead(ssize_t nread, const uv_buf_t* /*buf*/)
// Close server side of the connection.
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
}
...
...
@@ -432,4 +450,7 @@ inline void TcpConnection::OnUvWriteError(int error)
MS_WARN_DEV
(
"write error, closing the connection: %s"
,
uv_strerror
(
error
));
Close
();
// Notify the listener.
this
->
listener
->
OnTcpConnectionClosed
(
this
);
}
worker/src/handles/TcpServer.cpp
浏览文件 @
5c2208d5
...
...
@@ -77,11 +77,8 @@ void TcpServer::Close()
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
;
}
...
...
@@ -166,38 +163,36 @@ inline void TcpServer::OnUvConnection(int status)
if
(
err
!=
0
)
MS_ABORT
(
"uv_accept() failed: %s"
,
uv_strerror
(
err
));
// Insert the TcpConnection in the set.
this
->
connections
.
insert
(
connection
);
// Start receiving data.
try
{
// NOTE: This may throw.
connection
->
Start
();
// Notify the subclass.
UserOnNewTcpConnection
(
connection
);
}
catch
(
const
MediaSoupError
&
error
)
{
MS_ERROR
(
"cannot start the TCP connection, closing the connection: %s"
,
error
.
what
());
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_DEBUG_DEV
(
"TCP connection closed"
);
// Remove the TcpConnection from the set.
size_t
numErased
=
this
->
connections
.
erase
(
connection
);
// If the closed connection was not present in the set, do nothing else.
if
(
numErased
==
0
)
return
;
this
->
connections
.
erase
(
connection
);
// Notify the subclass.
UserOnTcpConnectionClosed
(
connection
,
isClosedByPeer
);
UserOnTcpConnectionClosed
(
connection
);
// Delete it.
delete
connection
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论