Skip to content

Commit

Permalink
For #1657, refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Nov 6, 2020
1 parent 5709ee1 commit 32c1832
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
3 changes: 3 additions & 0 deletions trunk/src/app/srs_app_caster_flv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ srs_error_t SrsAppCasterFlv::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa

SrsDynamicHttpConn::SrsDynamicHttpConn(ISrsResourceManager* cm, srs_netfd_t fd, SrsHttpServeMux* m, string cip, int cport)
{
// Create a identify for this client.
_srs_context->set_id(_srs_context->generate_id());

manager = cm;
sdk = NULL;
pprint = SrsPithyPrint::create_caster();
Expand Down
25 changes: 15 additions & 10 deletions trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,9 @@ srs_error_t SrsGoApiTcmalloc::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess

SrsHttpApi::SrsHttpApi(bool https, ISrsResourceManager* cm, srs_netfd_t fd, SrsHttpServeMux* m, string cip, int port)
{
// Create a identify for this client.
_srs_context->set_id(_srs_context->generate_id());

manager = cm;
skt = new SrsTcpConnection(fd);

Expand Down Expand Up @@ -1703,20 +1706,22 @@ srs_error_t SrsHttpApi::on_start()
{
srs_error_t err = srs_success;

srs_utime_t starttime = srs_update_system_time();
string crt_file = _srs_config->get_https_api_ssl_cert();
string key_file = _srs_config->get_https_api_ssl_key();
if (ssl && (err = ssl->handshake(key_file, crt_file)) != srs_success) {
return srs_error_wrap(err, "handshake");
}

if ((err = conn->set_jsonp(true)) != srs_success) {
return srs_error_wrap(err, "set jsonp");
}

int cost = srsu2msi(srs_update_system_time() - starttime);
srs_trace("https: api server done, use key %s and cert %s, cost=%dms",
key_file.c_str(), crt_file.c_str(), cost);
if (ssl) {
srs_utime_t starttime = srs_update_system_time();
string crt_file = _srs_config->get_https_api_ssl_cert();
string key_file = _srs_config->get_https_api_ssl_key();
if ((err = ssl->handshake(key_file, crt_file)) != srs_success) {
return srs_error_wrap(err, "handshake");
}

int cost = srsu2msi(srs_update_system_time() - starttime);
srs_trace("https: api server done, use key %s and cert %s, cost=%dms",
key_file.c_str(), crt_file.c_str(), cost);
}

return err;
}
Expand Down
23 changes: 14 additions & 9 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ void SrsHttpConn::expire()

SrsResponseOnlyHttpConn::SrsResponseOnlyHttpConn(bool https, ISrsResourceManager* cm, srs_netfd_t fd, ISrsHttpServeMux* m, string cip, int port)
{
// Create a identify for this client.
_srs_context->set_id(_srs_context->generate_id());

manager = cm;
skt = new SrsTcpConnection(fd);

Expand Down Expand Up @@ -373,16 +376,18 @@ srs_error_t SrsResponseOnlyHttpConn::on_start()
{
srs_error_t err = srs_success;

srs_utime_t starttime = srs_update_system_time();
string crt_file = _srs_config->get_https_stream_ssl_cert();
string key_file = _srs_config->get_https_stream_ssl_key();
if (ssl && (err = ssl->handshake(key_file, crt_file)) != srs_success) {
return srs_error_wrap(err, "handshake");
}
if (ssl) {
srs_utime_t starttime = srs_update_system_time();
string crt_file = _srs_config->get_https_stream_ssl_cert();
string key_file = _srs_config->get_https_stream_ssl_key();
if ((err = ssl->handshake(key_file, crt_file)) != srs_success) {
return srs_error_wrap(err, "handshake");
}

int cost = srsu2msi(srs_update_system_time() - starttime);
srs_trace("https: stream server done, use key %s and cert %s, cost=%dms",
key_file.c_str(), crt_file.c_str(), cost);
int cost = srsu2msi(srs_update_system_time() - starttime);
srs_trace("https: stream server done, use key %s and cert %s, cost=%dms",
key_file.c_str(), crt_file.c_str(), cost);
}

return err;
}
Expand Down
5 changes: 4 additions & 1 deletion trunk/src/app/srs_app_rtmp_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ SrsClientInfo::~SrsClientInfo()

SrsRtmpConn::SrsRtmpConn(SrsServer* svr, srs_netfd_t c, string cip, int cport)
{
// Create a identify for this client.
_srs_context->set_id(_srs_context->generate_id());

server = svr;

stfd = c;
Expand All @@ -117,7 +120,7 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* svr, srs_netfd_t c, string cip, int cport)
clk = new SrsWallClock();
kbps = new SrsKbps(clk);
kbps->set_io(skt, skt);
trd = new SrsSTCoroutine("rtmp", this);
trd = new SrsSTCoroutine("rtmp", this, _srs_context->get_id());

rtmp = new SrsRtmpServer(skt);
refer = new SrsRefer();
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,9 @@ srs_error_t SrsServer::fd_to_resource(SrsListenerType type, srs_netfd_t stfd, IS
return srs_error_new(ERROR_SYSTEM_PID_SET_FILE_INFO, "fcntl F_SETFD error! fd=%d", fd);
}
}

// The context id may change during creating the bellow objects.
SrsContextRestore(_srs_context->get_id());

if (type == SrsListenerRtmpStream) {
*pr = new SrsRtmpConn(this, stfd, ip, port);
Expand Down

0 comments on commit 32c1832

Please sign in to comment.