Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2015-12-24 17:25:05 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a7bf4bfda5ea17a54a5019b0db783bc70fc04602
a7bf4bfd
1 parent
49308ddd
refine code, ignore client when no ip.
隐藏空白字符变更
内嵌
并排对比
正在显示
10 个修改的文件
包含
73 行增加
和
56 行删除
trunk/src/app/srs_app_conn.cpp
trunk/src/app/srs_app_conn.hpp
trunk/src/app/srs_app_http_api.cpp
trunk/src/app/srs_app_http_api.hpp
trunk/src/app/srs_app_http_conn.cpp
trunk/src/app/srs_app_http_conn.hpp
trunk/src/app/srs_app_rtmp_conn.cpp
trunk/src/app/srs_app_rtmp_conn.hpp
trunk/src/app/srs_app_server.cpp
trunk/src/app/srs_app_server.hpp
trunk/src/app/srs_app_conn.cpp
查看文件 @
a7bf4bf
...
...
@@ -23,6 +23,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_conn.hpp>
using
namespace
std
;
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_app_utility.hpp>
...
...
@@ -36,11 +38,12 @@ IConnectionManager::~IConnectionManager()
{
}
SrsConnection
::
SrsConnection
(
IConnectionManager
*
cm
,
st_netfd_t
c
)
SrsConnection
::
SrsConnection
(
IConnectionManager
*
cm
,
st_netfd_t
c
,
string
cip
)
{
id
=
0
;
manager
=
cm
;
stfd
=
c
;
ip
=
cip
;
disposed
=
false
;
expired
=
false
;
create_time
=
srs_get_system_time_ms
();
...
...
@@ -112,8 +115,6 @@ int SrsConnection::cycle()
_srs_context
->
generate_id
();
id
=
_srs_context
->
get_id
();
ip
=
srs_get_peer_ip
(
st_netfd_fileno
(
stfd
));
int
oret
=
ret
=
do_cycle
();
// if socket io error, set to closed.
...
...
trunk/src/app/srs_app_conn.hpp
查看文件 @
a7bf4bf
...
...
@@ -110,7 +110,7 @@ protected:
*/
int64_t
create_time
;
public
:
SrsConnection
(
IConnectionManager
*
cm
,
st_netfd_t
c
);
SrsConnection
(
IConnectionManager
*
cm
,
st_netfd_t
c
,
std
::
string
cip
);
virtual
~
SrsConnection
();
// interface IKbpsDelta
public:
...
...
trunk/src/app/srs_app_http_api.cpp
查看文件 @
a7bf4bf
...
...
@@ -1309,8 +1309,8 @@ int SrsGoApiError::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
return
srs_api_response_code
(
w
,
r
,
100
);
}
SrsHttpApi
::
SrsHttpApi
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
SrsHttpServeMux
*
m
)
:
SrsConnection
(
cm
,
fd
)
SrsHttpApi
::
SrsHttpApi
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
SrsHttpServeMux
*
m
,
string
cip
)
:
SrsConnection
(
cm
,
fd
,
cip
)
{
mux
=
m
;
parser
=
new
SrsHttpParser
();
...
...
trunk/src/app/srs_app_http_api.hpp
查看文件 @
a7bf4bf
...
...
@@ -215,7 +215,7 @@ private:
bool
crossdomain_required
;
bool
crossdomain_enabled
;
public
:
SrsHttpApi
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
SrsHttpServeMux
*
m
);
SrsHttpApi
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
SrsHttpServeMux
*
m
,
std
::
string
cip
);
virtual
~
SrsHttpApi
();
// interface IKbpsDelta
public:
...
...
trunk/src/app/srs_app_http_conn.cpp
查看文件 @
a7bf4bf
...
...
@@ -1063,8 +1063,8 @@ int SrsHttpParser::on_body(http_parser* parser, const char* at, size_t length)
return
0
;
}
SrsHttpConn
::
SrsHttpConn
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
ISrsHttpServeMux
*
m
)
:
SrsConnection
(
cm
,
fd
)
SrsHttpConn
::
SrsHttpConn
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
ISrsHttpServeMux
*
m
,
string
cip
)
:
SrsConnection
(
cm
,
fd
,
cip
)
{
parser
=
new
SrsHttpParser
();
http_mux
=
m
;
...
...
@@ -1187,8 +1187,8 @@ int SrsHttpConn::on_disconnect(SrsRequest* req)
return
ret
;
}
SrsResponseOnlyHttpConn
::
SrsResponseOnlyHttpConn
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
ISrsHttpServeMux
*
m
)
:
SrsHttpConn
(
cm
,
fd
,
m
)
SrsResponseOnlyHttpConn
::
SrsResponseOnlyHttpConn
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
ISrsHttpServeMux
*
m
,
string
cip
)
:
SrsHttpConn
(
cm
,
fd
,
m
,
cip
)
{
}
...
...
trunk/src/app/srs_app_http_conn.hpp
查看文件 @
a7bf4bf
...
...
@@ -350,7 +350,7 @@ private:
SrsHttpParser
*
parser
;
ISrsHttpServeMux
*
http_mux
;
public
:
SrsHttpConn
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
ISrsHttpServeMux
*
m
);
SrsHttpConn
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
ISrsHttpServeMux
*
m
,
std
::
string
cip
);
virtual
~
SrsHttpConn
();
// interface IKbpsDelta
public:
...
...
@@ -381,7 +381,7 @@ private:
class
SrsResponseOnlyHttpConn
:
public
SrsHttpConn
{
public
:
SrsResponseOnlyHttpConn
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
ISrsHttpServeMux
*
m
);
SrsResponseOnlyHttpConn
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
ISrsHttpServeMux
*
m
,
std
::
string
cip
);
virtual
~
SrsResponseOnlyHttpConn
();
public
:
virtual
int
on_got_http_message
(
ISrsHttpMessage
*
msg
);
...
...
trunk/src/app/srs_app_rtmp_conn.cpp
查看文件 @
a7bf4bf
...
...
@@ -312,11 +312,11 @@ void SrsSimpleRtmpClient::set_recv_timeout(int64_t timeout)
}
#ifdef SRS_AUTO_KAFKA
SrsRtmpConn
::
SrsRtmpConn
(
SrsServer
*
svr
,
ISrsKafkaCluster
*
k
,
st_netfd_t
c
)
SrsRtmpConn
::
SrsRtmpConn
(
SrsServer
*
svr
,
ISrsKafkaCluster
*
k
,
st_netfd_t
c
,
string
cip
)
#else
SrsRtmpConn
::
SrsRtmpConn
(
SrsServer
*
svr
,
st_netfd_t
c
)
SrsRtmpConn
::
SrsRtmpConn
(
SrsServer
*
svr
,
st_netfd_t
c
,
string
cip
)
#endif
:
SrsConnection
(
svr
,
c
)
:
SrsConnection
(
svr
,
c
,
cip
)
{
server
=
svr
;
#ifdef SRS_AUTO_KAFKA
...
...
@@ -373,7 +373,7 @@ int SrsRtmpConn::do_cycle()
{
int
ret
=
ERROR_SUCCESS
;
srs_trace
(
"RTMP client ip=%s
"
,
ip
.
c_str
(
));
srs_trace
(
"RTMP client ip=%s
, fd=%d"
,
ip
.
c_str
(),
st_netfd_fileno
(
stfd
));
// notify kafka cluster.
#ifdef SRS_AUTO_KAFKA
...
...
trunk/src/app/srs_app_rtmp_conn.hpp
查看文件 @
a7bf4bf
...
...
@@ -144,9 +144,9 @@ private:
#endif
public
:
#ifdef SRS_AUTO_KAFKA
SrsRtmpConn
(
SrsServer
*
svr
,
ISrsKafkaCluster
*
k
,
st_netfd_t
c
);
SrsRtmpConn
(
SrsServer
*
svr
,
ISrsKafkaCluster
*
k
,
st_netfd_t
c
,
std
::
string
cip
);
#else
SrsRtmpConn
(
SrsServer
*
svr
,
st_netfd_t
c
);
SrsRtmpConn
(
SrsServer
*
svr
,
st_netfd_t
c
,
std
::
string
cip
);
#endif
virtual
~
SrsRtmpConn
();
public
:
...
...
trunk/src/app/srs_app_server.cpp
查看文件 @
a7bf4bf
...
...
@@ -1241,25 +1241,55 @@ void SrsServer::resample_kbps()
srs_update_rtmp_server
((
int
)
conns
.
size
(),
kbps
);
}
int
SrsServer
::
accept_client
(
SrsListenerType
type
,
st_netfd_t
client_
stfd
)
int
SrsServer
::
accept_client
(
SrsListenerType
type
,
st_netfd_t
stfd
)
{
int
ret
=
ERROR_SUCCESS
;
int
fd
=
st_netfd_fileno
(
client_stfd
);
SrsConnection
*
conn
=
fd2conn
(
type
,
stfd
);
if
(
conn
==
NULL
)
{
srs_close_stfd
(
stfd
);
return
ERROR_SUCCESS
;
}
srs_assert
(
conn
);
// directly enqueue, the cycle thread will remove the client.
conns
.
push_back
(
conn
);
srs_verbose
(
"add conn to vector."
);
// cycle will start process thread and when finished remove the client.
// @remark never use the conn, for it maybe destroyed.
if
((
ret
=
conn
->
start
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
srs_verbose
(
"accept client finished. conns=%d, ret=%d"
,
(
int
)
conns
.
size
(),
ret
);
return
ret
;
}
SrsConnection
*
SrsServer
::
fd2conn
(
SrsListenerType
type
,
st_netfd_t
stfd
)
{
int
ret
=
ERROR_SUCCESS
;
int
fd
=
st_netfd_fileno
(
stfd
);
string
ip
=
srs_get_peer_ip
(
fd
);
// for some keep alive application, for example, the keepalived,
// will send some tcp packet which we cann't got the ip,
// we just ignore it.
if
(
ip
.
empty
())
{
srs_info
(
"ignore empty ip client, fd=%d."
,
fd
);
return
NULL
;
}
// check connection limitation.
int
max_connections
=
_srs_config
->
get_max_connections
();
if
(
handler
&&
(
ret
=
handler
->
on_accept_client
(
max_connections
,
(
int
)
conns
.
size
())
!=
ERROR_SUCCESS
))
{
srs_error
(
"handle accept client failed, drop client: "
"clients=%d, max=%d, fd=%d. ret=%d"
,
(
int
)
conns
.
size
(),
max_connections
,
fd
,
ret
);
srs_close_stfd
(
client_stfd
);
return
ERROR_SUCCESS
;
srs_error
(
"handle accept client failed, drop client: clients=%d, max=%d, fd=%d. ret=%d"
,
(
int
)
conns
.
size
(),
max_connections
,
fd
,
ret
);
return
NULL
;
}
if
((
int
)
conns
.
size
()
>=
max_connections
)
{
srs_error
(
"exceed the max connections, drop client: "
"clients=%d, max=%d, fd=%d"
,
(
int
)
conns
.
size
(),
max_connections
,
fd
);
srs_close_stfd
(
client_stfd
);
return
ERROR_SUCCESS
;
srs_error
(
"exceed the max connections, drop client: clients=%d, max=%d, fd=%d"
,
(
int
)
conns
.
size
(),
max_connections
,
fd
);
return
NULL
;
}
// avoid fd leak when fork.
...
...
@@ -1269,56 +1299,40 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
if
((
val
=
fcntl
(
fd
,
F_GETFD
,
0
))
<
0
)
{
ret
=
ERROR_SYSTEM_PID_GET_FILE_INFO
;
srs_error
(
"fnctl F_GETFD error! fd=%d. ret=%#x"
,
fd
,
ret
);
srs_close_stfd
(
client_stfd
);
return
ret
;
return
NULL
;
}
val
|=
FD_CLOEXEC
;
if
(
fcntl
(
fd
,
F_SETFD
,
val
)
<
0
)
{
ret
=
ERROR_SYSTEM_PID_SET_FILE_INFO
;
srs_error
(
"fcntl F_SETFD error! fd=%d ret=%#x"
,
fd
,
ret
);
srs_close_stfd
(
client_stfd
);
return
ret
;
return
NULL
;
}
}
SrsConnection
*
conn
=
NULL
;
if
(
type
==
SrsListenerRtmpStream
)
{
conn
=
new
SrsRtmpConn
(
this
,
kafka
,
client_stfd
);
conn
=
new
SrsRtmpConn
(
this
,
kafka
,
stfd
,
ip
);
}
else
if
(
type
==
SrsListenerHttpApi
)
{
#ifdef SRS_AUTO_HTTP_API
conn
=
new
SrsHttpApi
(
this
,
client_stfd
,
http_api_mux
);
conn
=
new
SrsHttpApi
(
this
,
stfd
,
http_api_mux
,
ip
);
#else
srs_warn
(
"close http client for server not support http-api"
);
srs_close_stfd
(
client_
stfd
);
srs_close_stfd
(
stfd
);
return
ret
;
#endif
}
else
if
(
type
==
SrsListenerHttpStream
)
{
#ifdef SRS_AUTO_HTTP_SERVER
conn
=
new
SrsResponseOnlyHttpConn
(
this
,
client_stfd
,
http_server
);
conn
=
new
SrsResponseOnlyHttpConn
(
this
,
stfd
,
http_server
,
ip
);
#else
srs_warn
(
"close http client for server not support http-server"
);
srs_close_stfd
(
client_stfd
);
return
ret
;
return
NULL
;
#endif
}
else
{
// TODO: FIXME: handler others
}
srs_assert
(
conn
);
// directly enqueue, the cycle thread will remove the client.
conns
.
push_back
(
conn
);
srs_verbose
(
"add conn to vector."
);
// cycle will start process thread and when finished remove the client.
// @remark never use the conn, for it maybe destroyed.
if
((
ret
=
conn
->
start
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
srs_verbose
(
"conn started success."
);
srs_verbose
(
"accept client finished. conns=%d, ret=%d"
,
(
int
)
conns
.
size
(),
ret
);
return
ret
;
return
conn
;
}
void
SrsServer
::
remove
(
SrsConnection
*
conn
)
...
...
trunk/src/app/srs_app_server.hpp
查看文件 @
a7bf4bf
...
...
@@ -365,9 +365,11 @@ public:
* when listener got a fd, notice server to accept it.
* @param type, the client type, used to create concrete connection,
* for instance RTMP connection to serve client.
* @param
client_
stfd, the client fd in st boxed, the underlayer fd.
* @param stfd, the client fd in st boxed, the underlayer fd.
*/
virtual
int
accept_client
(
SrsListenerType
type
,
st_netfd_t
client_stfd
);
virtual
int
accept_client
(
SrsListenerType
type
,
st_netfd_t
stfd
);
private
:
virtual
SrsConnection
*
fd2conn
(
SrsListenerType
type
,
st_netfd_t
stfd
);
// IConnectionManager
public:
/**
...
...
请
注册
或
登录
后发表评论