正在显示
6 个修改的文件
包含
42 行增加
和
39 行删除
| @@ -55,7 +55,7 @@ using namespace std; | @@ -55,7 +55,7 @@ using namespace std; | ||
| 55 | 55 | ||
| 56 | using namespace _srs_internal; | 56 | using namespace _srs_internal; |
| 57 | 57 | ||
| 58 | -// the version to identify the core. | 58 | +// @global the version to identify the core. |
| 59 | const char* _srs_version = "XCORE-"RTMP_SIG_SRS_SERVER; | 59 | const char* _srs_version = "XCORE-"RTMP_SIG_SRS_SERVER; |
| 60 | 60 | ||
| 61 | #define SRS_WIKI_URL_LOG "https://github.com/ossrs/srs/wiki/v1_CN_SrsLog" | 61 | #define SRS_WIKI_URL_LOG "https://github.com/ossrs/srs/wiki/v1_CN_SrsLog" |
| @@ -4194,7 +4194,7 @@ bool SrsConfig::get_utc_time() | @@ -4194,7 +4194,7 @@ bool SrsConfig::get_utc_time() | ||
| 4194 | } | 4194 | } |
| 4195 | 4195 | ||
| 4196 | string SrsConfig::get_work_dir() { | 4196 | string SrsConfig::get_work_dir() { |
| 4197 | - static string DEFAULT = ""; | 4197 | + static string DEFAULT = "./"; |
| 4198 | 4198 | ||
| 4199 | SrsConfDirective* conf = root->get("work_dir"); | 4199 | SrsConfDirective* conf = root->get("work_dir"); |
| 4200 | if( !conf || conf->arg0().empty()) { | 4200 | if( !conf || conf->arg0().empty()) { |
| @@ -125,7 +125,7 @@ extern std::string srs_config_bool2switch(const std::string& sbool); | @@ -125,7 +125,7 @@ extern std::string srs_config_bool2switch(const std::string& sbool); | ||
| 125 | */ | 125 | */ |
| 126 | extern int srs_config_transform_vhost(SrsConfDirective* root); | 126 | extern int srs_config_transform_vhost(SrsConfDirective* root); |
| 127 | 127 | ||
| 128 | -// global config | 128 | +// @global config object. |
| 129 | extern SrsConfig* _srs_config; | 129 | extern SrsConfig* _srs_config; |
| 130 | 130 | ||
| 131 | /** | 131 | /** |
| @@ -1318,6 +1318,7 @@ SrsConnection* SrsServer::fd2conn(SrsListenerType type, st_netfd_t stfd) | @@ -1318,6 +1318,7 @@ SrsConnection* SrsServer::fd2conn(SrsListenerType type, st_netfd_t stfd) | ||
| 1318 | } | 1318 | } |
| 1319 | 1319 | ||
| 1320 | SrsConnection* conn = NULL; | 1320 | SrsConnection* conn = NULL; |
| 1321 | + bool close_for_not_served = false; | ||
| 1321 | 1322 | ||
| 1322 | if (type == SrsListenerRtmpStream) { | 1323 | if (type == SrsListenerRtmpStream) { |
| 1323 | conn = new SrsRtmpConn(this, stfd, ip); | 1324 | conn = new SrsRtmpConn(this, stfd, ip); |
| @@ -1326,18 +1327,23 @@ SrsConnection* SrsServer::fd2conn(SrsListenerType type, st_netfd_t stfd) | @@ -1326,18 +1327,23 @@ SrsConnection* SrsServer::fd2conn(SrsListenerType type, st_netfd_t stfd) | ||
| 1326 | conn = new SrsHttpApi(this, stfd, http_api_mux, ip); | 1327 | conn = new SrsHttpApi(this, stfd, http_api_mux, ip); |
| 1327 | #else | 1328 | #else |
| 1328 | srs_warn("close http client for server not support http-api"); | 1329 | srs_warn("close http client for server not support http-api"); |
| 1329 | - srs_close_stfd(stfd); | ||
| 1330 | - return ret; | 1330 | + close_for_not_served = true; |
| 1331 | #endif | 1331 | #endif |
| 1332 | } else if (type == SrsListenerHttpStream) { | 1332 | } else if (type == SrsListenerHttpStream) { |
| 1333 | #ifdef SRS_AUTO_HTTP_SERVER | 1333 | #ifdef SRS_AUTO_HTTP_SERVER |
| 1334 | conn = new SrsResponseOnlyHttpConn(this, stfd, http_server, ip); | 1334 | conn = new SrsResponseOnlyHttpConn(this, stfd, http_server, ip); |
| 1335 | #else | 1335 | #else |
| 1336 | srs_warn("close http client for server not support http-server"); | 1336 | srs_warn("close http client for server not support http-server"); |
| 1337 | - return NULL; | 1337 | + close_for_not_served = true; |
| 1338 | #endif | 1338 | #endif |
| 1339 | } else { | 1339 | } else { |
| 1340 | // TODO: FIXME: handler others | 1340 | // TODO: FIXME: handler others |
| 1341 | + srs_assert(false); | ||
| 1342 | + } | ||
| 1343 | + | ||
| 1344 | + if (close_for_not_served) { | ||
| 1345 | + srs_close_stfd(stfd); | ||
| 1346 | + return NULL; | ||
| 1341 | } | 1347 | } |
| 1342 | 1348 | ||
| 1343 | return conn; | 1349 | return conn; |
| @@ -124,10 +124,10 @@ public: | @@ -124,10 +124,10 @@ public: | ||
| 124 | virtual int set_id(int v); | 124 | virtual int set_id(int v); |
| 125 | }; | 125 | }; |
| 126 | 126 | ||
| 127 | -// user must provides a log object | 127 | +// @global user must provides a log object |
| 128 | extern ISrsLog* _srs_log; | 128 | extern ISrsLog* _srs_log; |
| 129 | 129 | ||
| 130 | -// user must implements the LogContext and define a global instance. | 130 | +// @global user must implements the LogContext and define a global instance. |
| 131 | extern ISrsThreadContext* _srs_context; | 131 | extern ISrsThreadContext* _srs_context; |
| 132 | 132 | ||
| 133 | // donot print method | 133 | // donot print method |
| @@ -52,15 +52,11 @@ using namespace std; | @@ -52,15 +52,11 @@ using namespace std; | ||
| 52 | // pre-declare | 52 | // pre-declare |
| 53 | int proxy_hls2rtmp(std::string hls, std::string rtmp); | 53 | int proxy_hls2rtmp(std::string hls, std::string rtmp); |
| 54 | 54 | ||
| 55 | -// for the main objects(server, config, log, context), | ||
| 56 | -// never subscribe handler in constructor, | ||
| 57 | -// instead, subscribe handler in initialize method. | ||
| 58 | -// kernel module. | 55 | +// @global log and context. |
| 59 | ISrsLog* _srs_log = new SrsFastLog(); | 56 | ISrsLog* _srs_log = new SrsFastLog(); |
| 60 | ISrsThreadContext* _srs_context = new ISrsThreadContext(); | 57 | ISrsThreadContext* _srs_context = new ISrsThreadContext(); |
| 61 | -// app module. | 58 | +// @global config object for app module. |
| 62 | SrsConfig* _srs_config = NULL; | 59 | SrsConfig* _srs_config = NULL; |
| 63 | -SrsServer* _srs_server = NULL; | ||
| 64 | 60 | ||
| 65 | #if defined(SRS_AUTO_HTTP_CORE) | 61 | #if defined(SRS_AUTO_HTTP_CORE) |
| 66 | 62 |
| @@ -46,21 +46,19 @@ using namespace std; | @@ -46,21 +46,19 @@ using namespace std; | ||
| 46 | #include <srs_kernel_utility.hpp> | 46 | #include <srs_kernel_utility.hpp> |
| 47 | #include <srs_core_performance.hpp> | 47 | #include <srs_core_performance.hpp> |
| 48 | #include <srs_app_utility.hpp> | 48 | #include <srs_app_utility.hpp> |
| 49 | +#include <srs_core_autofree.hpp> | ||
| 49 | 50 | ||
| 50 | // pre-declare | 51 | // pre-declare |
| 51 | -int run(); | ||
| 52 | -int run_master(); | 52 | +int run(SrsServer* svr); |
| 53 | +int run_master(SrsServer* svr); | ||
| 53 | 54 | ||
| 54 | -// for the main objects(server, config, log, context), | ||
| 55 | -// never subscribe handler in constructor, | ||
| 56 | -// instead, subscribe handler in initialize method. | ||
| 57 | -// kernel module. | 55 | +// @global log and context. |
| 58 | ISrsLog* _srs_log = new SrsFastLog(); | 56 | ISrsLog* _srs_log = new SrsFastLog(); |
| 59 | -ISrsThreadContext* _srs_context = new SrsThreadContext(); | ||
| 60 | -// app module. | 57 | +ISrsThreadContext* _srs_context = new ISrsThreadContext(); |
| 58 | +// @global config object for app module. | ||
| 61 | SrsConfig* _srs_config = new SrsConfig(); | 59 | SrsConfig* _srs_config = new SrsConfig(); |
| 62 | -SrsServer* _srs_server = new SrsServer(); | ||
| 63 | -// version of srs, which can grep keyword "XCORE" | 60 | + |
| 61 | +// @global version of srs, which can grep keyword "XCORE" | ||
| 64 | extern const char* _srs_version; | 62 | extern const char* _srs_version; |
| 65 | 63 | ||
| 66 | /** | 64 | /** |
| @@ -315,24 +313,27 @@ int main(int argc, char** argv) | @@ -315,24 +313,27 @@ int main(int argc, char** argv) | ||
| 315 | 313 | ||
| 316 | // features | 314 | // features |
| 317 | show_macro_features(); | 315 | show_macro_features(); |
| 318 | - | 316 | + |
| 317 | + SrsServer* svr = new SrsServer(); | ||
| 318 | + SrsAutoFree(SrsServer, svr); | ||
| 319 | + | ||
| 319 | /** | 320 | /** |
| 320 | * we do nothing in the constructor of server, | 321 | * we do nothing in the constructor of server, |
| 321 | * and use initialize to create members, set hooks for instance the reload handler, | 322 | * and use initialize to create members, set hooks for instance the reload handler, |
| 322 | * all initialize will done in this stage. | 323 | * all initialize will done in this stage. |
| 323 | */ | 324 | */ |
| 324 | - if ((ret = _srs_server->initialize(NULL)) != ERROR_SUCCESS) { | 325 | + if ((ret = svr->initialize(NULL)) != ERROR_SUCCESS) { |
| 325 | return ret; | 326 | return ret; |
| 326 | } | 327 | } |
| 327 | 328 | ||
| 328 | - return run(); | 329 | + return run(svr); |
| 329 | } | 330 | } |
| 330 | 331 | ||
| 331 | -int run() | 332 | +int run(SrsServer* svr) |
| 332 | { | 333 | { |
| 333 | // if not deamon, directly run master. | 334 | // if not deamon, directly run master. |
| 334 | if (!_srs_config->get_deamon()) { | 335 | if (!_srs_config->get_deamon()) { |
| 335 | - return run_master(); | 336 | + return run_master(svr); |
| 336 | } | 337 | } |
| 337 | 338 | ||
| 338 | srs_trace("start deamon mode..."); | 339 | srs_trace("start deamon mode..."); |
| @@ -370,42 +371,42 @@ int run() | @@ -370,42 +371,42 @@ int run() | ||
| 370 | // son | 371 | // son |
| 371 | srs_trace("son(deamon) process running."); | 372 | srs_trace("son(deamon) process running."); |
| 372 | 373 | ||
| 373 | - return run_master(); | 374 | + return run_master(svr); |
| 374 | } | 375 | } |
| 375 | 376 | ||
| 376 | -int run_master() | 377 | +int run_master(SrsServer* svr) |
| 377 | { | 378 | { |
| 378 | int ret = ERROR_SUCCESS; | 379 | int ret = ERROR_SUCCESS; |
| 379 | 380 | ||
| 380 | - if ((ret = _srs_server->initialize_st()) != ERROR_SUCCESS) { | 381 | + if ((ret = svr->initialize_st()) != ERROR_SUCCESS) { |
| 381 | return ret; | 382 | return ret; |
| 382 | } | 383 | } |
| 383 | 384 | ||
| 384 | - if ((ret = _srs_server->initialize_signal()) != ERROR_SUCCESS) { | 385 | + if ((ret = svr->initialize_signal()) != ERROR_SUCCESS) { |
| 385 | return ret; | 386 | return ret; |
| 386 | } | 387 | } |
| 387 | 388 | ||
| 388 | - if ((ret = _srs_server->acquire_pid_file()) != ERROR_SUCCESS) { | 389 | + if ((ret = svr->acquire_pid_file()) != ERROR_SUCCESS) { |
| 389 | return ret; | 390 | return ret; |
| 390 | } | 391 | } |
| 391 | 392 | ||
| 392 | - if ((ret = _srs_server->listen()) != ERROR_SUCCESS) { | 393 | + if ((ret = svr->listen()) != ERROR_SUCCESS) { |
| 393 | return ret; | 394 | return ret; |
| 394 | } | 395 | } |
| 395 | 396 | ||
| 396 | - if ((ret = _srs_server->register_signal()) != ERROR_SUCCESS) { | 397 | + if ((ret = svr->register_signal()) != ERROR_SUCCESS) { |
| 397 | return ret; | 398 | return ret; |
| 398 | } | 399 | } |
| 399 | 400 | ||
| 400 | - if ((ret = _srs_server->http_handle()) != ERROR_SUCCESS) { | 401 | + if ((ret = svr->http_handle()) != ERROR_SUCCESS) { |
| 401 | return ret; | 402 | return ret; |
| 402 | } | 403 | } |
| 403 | 404 | ||
| 404 | - if ((ret = _srs_server->ingest()) != ERROR_SUCCESS) { | 405 | + if ((ret = svr->ingest()) != ERROR_SUCCESS) { |
| 405 | return ret; | 406 | return ret; |
| 406 | } | 407 | } |
| 407 | 408 | ||
| 408 | - if ((ret = _srs_server->cycle()) != ERROR_SUCCESS) { | 409 | + if ((ret = svr->cycle()) != ERROR_SUCCESS) { |
| 409 | return ret; | 410 | return ret; |
| 410 | } | 411 | } |
| 411 | 412 |
-
请 注册 或 登录 后发表评论