winlin

refine code, move the order of functions.

@@ -535,271 +535,6 @@ int SrsConfig::reload() @@ -535,271 +535,6 @@ int SrsConfig::reload()
535 return reload_conf(&conf); 535 return reload_conf(&conf);
536 } 536 }
537 537
538 -int SrsConfig::reload_conf(SrsConfig* conf)  
539 -{  
540 - int ret = ERROR_SUCCESS;  
541 -  
542 - SrsConfDirective* old_root = root;  
543 - SrsAutoFree(SrsConfDirective, old_root);  
544 -  
545 - root = conf->root;  
546 - conf->root = NULL;  
547 -  
548 - // merge config.  
549 - std::vector<ISrsReloadHandler*>::iterator it;  
550 -  
551 - // never support reload:  
552 - // daemon  
553 - //  
554 - // always support reload without additional code:  
555 - // chunk_size, ff_log_dir,  
556 - // bandcheck, http_hooks, heartbeat,  
557 - // token_traverse, debug_srs_upnode,  
558 - // security  
559 -  
560 - // merge config: max_connections  
561 - if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) {  
562 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
563 - ISrsReloadHandler* subscribe = *it;  
564 - if ((ret = subscribe->on_reload_max_conns()) != ERROR_SUCCESS) {  
565 - srs_error("notify subscribes reload max_connections failed. ret=%d", ret);  
566 - return ret;  
567 - }  
568 - }  
569 - srs_trace("reload max_connections success.");  
570 - }  
571 -  
572 - // merge config: listen  
573 - if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) {  
574 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
575 - ISrsReloadHandler* subscribe = *it;  
576 - if ((ret = subscribe->on_reload_listen()) != ERROR_SUCCESS) {  
577 - srs_error("notify subscribes reload listen failed. ret=%d", ret);  
578 - return ret;  
579 - }  
580 - }  
581 - srs_trace("reload listen success.");  
582 - }  
583 -  
584 - // merge config: pid  
585 - if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {  
586 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
587 - ISrsReloadHandler* subscribe = *it;  
588 - if ((ret = subscribe->on_reload_pid()) != ERROR_SUCCESS) {  
589 - srs_error("notify subscribes reload pid failed. ret=%d", ret);  
590 - return ret;  
591 - }  
592 - }  
593 - srs_trace("reload pid success.");  
594 - }  
595 -  
596 - // merge config: srs_log_tank  
597 - if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) {  
598 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
599 - ISrsReloadHandler* subscribe = *it;  
600 - if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) {  
601 - srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret);  
602 - return ret;  
603 - }  
604 - }  
605 - srs_trace("reload srs_log_tank success.");  
606 - }  
607 -  
608 - // merge config: srs_log_level  
609 - if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) {  
610 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
611 - ISrsReloadHandler* subscribe = *it;  
612 - if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) {  
613 - srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret);  
614 - return ret;  
615 - }  
616 - }  
617 - srs_trace("reload srs_log_level success.");  
618 - }  
619 -  
620 - // merge config: srs_log_file  
621 - if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) {  
622 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
623 - ISrsReloadHandler* subscribe = *it;  
624 - if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) {  
625 - srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret);  
626 - return ret;  
627 - }  
628 - }  
629 - srs_trace("reload srs_log_file success.");  
630 - }  
631 -  
632 - // merge config: pithy_print_ms  
633 - if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) {  
634 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
635 - ISrsReloadHandler* subscribe = *it;  
636 - if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) {  
637 - srs_error("notify subscribes pithy_print_ms listen failed. ret=%d", ret);  
638 - return ret;  
639 - }  
640 - }  
641 - srs_trace("reload pithy_print_ms success.");  
642 - }  
643 -  
644 - // merge config: http_api  
645 - if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) {  
646 - return ret;  
647 - }  
648 -  
649 - // merge config: http_stream  
650 - if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) {  
651 - return ret;  
652 - }  
653 -  
654 - // TODO: FIXME: support reload stream_caster.  
655 -  
656 - // merge config: vhost  
657 - if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) {  
658 - return ret;  
659 - }  
660 -  
661 - return ret;  
662 -}  
663 -  
664 -int SrsConfig::reload_http_api(SrsConfDirective* old_root)  
665 -{  
666 - int ret = ERROR_SUCCESS;  
667 -  
668 - // merge config.  
669 - std::vector<ISrsReloadHandler*>::iterator it;  
670 -  
671 - // state graph  
672 - // old_http_api new_http_api  
673 - // DISABLED => ENABLED  
674 - // ENABLED => DISABLED  
675 - // ENABLED => ENABLED (modified)  
676 -  
677 - SrsConfDirective* new_http_api = root->get("http_api");  
678 - SrsConfDirective* old_http_api = old_root->get("http_api");  
679 -  
680 - // DISABLED => ENABLED  
681 - if (!get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)) {  
682 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
683 - ISrsReloadHandler* subscribe = *it;  
684 - if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {  
685 - srs_error("notify subscribes http_api disabled=>enabled failed. ret=%d", ret);  
686 - return ret;  
687 - }  
688 - }  
689 - srs_trace("reload disabled=>enabled http_api success.");  
690 -  
691 - return ret;  
692 - }  
693 -  
694 - // ENABLED => DISABLED  
695 - if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) {  
696 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
697 - ISrsReloadHandler* subscribe = *it;  
698 - if ((ret = subscribe->on_reload_http_api_disabled()) != ERROR_SUCCESS) {  
699 - srs_error("notify subscribes http_api enabled=>disabled failed. ret=%d", ret);  
700 - return ret;  
701 - }  
702 - }  
703 - srs_trace("reload enabled=>disabled http_api success.");  
704 -  
705 - return ret;  
706 - }  
707 -  
708 - // ENABLED => ENABLED (modified)  
709 - if (get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)  
710 - && !srs_directive_equals(old_http_api, new_http_api)  
711 - ) {  
712 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
713 - ISrsReloadHandler* subscribe = *it;  
714 - if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {  
715 - srs_error("notify subscribes http_api enabled modified failed. ret=%d", ret);  
716 - return ret;  
717 - }  
718 - }  
719 - srs_trace("reload enabled modified http_api success.");  
720 -  
721 - return ret;  
722 - }  
723 -  
724 - srs_trace("reload http_api not changed success.");  
725 -  
726 - return ret;  
727 -}  
728 -  
729 -int SrsConfig::reload_http_stream(SrsConfDirective* old_root)  
730 -{  
731 - int ret = ERROR_SUCCESS;  
732 -  
733 - // merge config.  
734 - std::vector<ISrsReloadHandler*>::iterator it;  
735 -  
736 - // state graph  
737 - // old_http_stream new_http_stream  
738 - // DISABLED => ENABLED  
739 - // ENABLED => DISABLED  
740 - // ENABLED => ENABLED (modified)  
741 -  
742 - SrsConfDirective* new_http_stream = root->get("http_stream");  
743 - // http_stream rename to http_server in SRS2.  
744 - if (!new_http_stream) {  
745 - new_http_stream = root->get("http_server");  
746 - }  
747 -  
748 - SrsConfDirective* old_http_stream = old_root->get("http_stream");  
749 - // http_stream rename to http_server in SRS2.  
750 - if (!old_http_stream) {  
751 - old_http_stream = root->get("http_server");  
752 - }  
753 -  
754 - // DISABLED => ENABLED  
755 - if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) {  
756 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
757 - ISrsReloadHandler* subscribe = *it;  
758 - if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) {  
759 - srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret);  
760 - return ret;  
761 - }  
762 - }  
763 - srs_trace("reload disabled=>enabled http_stream success.");  
764 -  
765 - return ret;  
766 - }  
767 -  
768 - // ENABLED => DISABLED  
769 - if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) {  
770 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
771 - ISrsReloadHandler* subscribe = *it;  
772 - if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) {  
773 - srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret);  
774 - return ret;  
775 - }  
776 - }  
777 - srs_trace("reload enabled=>disabled http_stream success.");  
778 -  
779 - return ret;  
780 - }  
781 -  
782 - // ENABLED => ENABLED (modified)  
783 - if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)  
784 - && !srs_directive_equals(old_http_stream, new_http_stream)  
785 - ) {  
786 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
787 - ISrsReloadHandler* subscribe = *it;  
788 - if ((ret = subscribe->on_reload_http_stream_updated()) != ERROR_SUCCESS) {  
789 - srs_error("notify subscribes http_stream enabled modified failed. ret=%d", ret);  
790 - return ret;  
791 - }  
792 - }  
793 - srs_trace("reload enabled modified http_stream success.");  
794 -  
795 - return ret;  
796 - }  
797 -  
798 - srs_trace("reload http_stream not changed success.");  
799 -  
800 - return ret;  
801 -}  
802 -  
803 int SrsConfig::reload_vhost(SrsConfDirective* old_root) 538 int SrsConfig::reload_vhost(SrsConfDirective* old_root)
804 { 539 {
805 int ret = ERROR_SUCCESS; 540 int ret = ERROR_SUCCESS;
@@ -1004,83 +739,348 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) @@ -1004,83 +739,348 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
1004 if (!srs_directive_equals(new_vhost->get("chunk_size"), old_vhost->get("chunk_size"))) { 739 if (!srs_directive_equals(new_vhost->get("chunk_size"), old_vhost->get("chunk_size"))) {
1005 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 740 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
1006 ISrsReloadHandler* subscribe = *it; 741 ISrsReloadHandler* subscribe = *it;
1007 - if ((ret = subscribe->on_reload_vhost_chunk_size(vhost)) != ERROR_SUCCESS) {  
1008 - srs_error("vhost %s notify subscribes chunk_size failed. ret=%d", vhost.c_str(), ret); 742 + if ((ret = subscribe->on_reload_vhost_chunk_size(vhost)) != ERROR_SUCCESS) {
  743 + srs_error("vhost %s notify subscribes chunk_size failed. ret=%d", vhost.c_str(), ret);
  744 + return ret;
  745 + }
  746 + }
  747 + srs_trace("vhost %s reload chunk_size success.", vhost.c_str());
  748 + }
  749 + // mw, only one per vhost
  750 + if (!srs_directive_equals(new_vhost->get("mw_latency"), old_vhost->get("mw_latency"))) {
  751 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  752 + ISrsReloadHandler* subscribe = *it;
  753 + if ((ret = subscribe->on_reload_vhost_mw(vhost)) != ERROR_SUCCESS) {
  754 + srs_error("vhost %s notify subscribes mw failed. ret=%d", vhost.c_str(), ret);
  755 + return ret;
  756 + }
  757 + }
  758 + srs_trace("vhost %s reload mw success.", vhost.c_str());
  759 + }
  760 + // min_latency, only one per vhost
  761 + if (!srs_directive_equals(new_vhost->get("min_latency"), old_vhost->get("min_latency"))) {
  762 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  763 + ISrsReloadHandler* subscribe = *it;
  764 + if ((ret = subscribe->on_reload_vhost_realtime(vhost)) != ERROR_SUCCESS) {
  765 + srs_error("vhost %s notify subscribes min_latency failed. ret=%d", vhost.c_str(), ret);
  766 + return ret;
  767 + }
  768 + }
  769 + srs_trace("vhost %s reload min_latency success.", vhost.c_str());
  770 + }
  771 + // http, only one per vhost.
  772 + if (!srs_directive_equals(new_vhost->get("http"), old_vhost->get("http"))) {
  773 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  774 + ISrsReloadHandler* subscribe = *it;
  775 + if ((ret = subscribe->on_reload_vhost_http_updated()) != ERROR_SUCCESS) {
  776 + srs_error("vhost %s notify subscribes http failed. ret=%d", vhost.c_str(), ret);
  777 + return ret;
  778 + }
  779 + }
  780 + srs_trace("vhost %s reload http success.", vhost.c_str());
  781 + }
  782 + // http_static, only one per vhost.
  783 + // @remark, http_static introduced as alias of http.
  784 + if (!srs_directive_equals(new_vhost->get("http_static"), old_vhost->get("http_static"))) {
  785 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  786 + ISrsReloadHandler* subscribe = *it;
  787 + if ((ret = subscribe->on_reload_vhost_http_updated()) != ERROR_SUCCESS) {
  788 + srs_error("vhost %s notify subscribes http_static failed. ret=%d", vhost.c_str(), ret);
  789 + return ret;
  790 + }
  791 + }
  792 + srs_trace("vhost %s reload http_static success.", vhost.c_str());
  793 + }
  794 + // http_remux, only one per vhost.
  795 + if (!srs_directive_equals(new_vhost->get("http_remux"), old_vhost->get("http_remux"))) {
  796 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  797 + ISrsReloadHandler* subscribe = *it;
  798 + if ((ret = subscribe->on_reload_vhost_http_remux_updated(vhost)) != ERROR_SUCCESS) {
  799 + srs_error("vhost %s notify subscribes http_remux failed. ret=%d", vhost.c_str(), ret);
  800 + return ret;
  801 + }
  802 + }
  803 + srs_trace("vhost %s reload http_remux success.", vhost.c_str());
  804 + }
  805 + // transcode, many per vhost.
  806 + if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) {
  807 + return ret;
  808 + }
  809 + // ingest, many per vhost.
  810 + if ((ret = reload_ingest(new_vhost, old_vhost)) != ERROR_SUCCESS) {
  811 + return ret;
  812 + }
  813 + continue;
  814 + }
  815 + srs_trace("ignore reload vhost, enabled old: %d, new: %d",
  816 + get_vhost_enabled(old_vhost), get_vhost_enabled(new_vhost));
  817 + }
  818 +
  819 + return ret;
  820 +}
  821 +
  822 +int SrsConfig::reload_conf(SrsConfig* conf)
  823 +{
  824 + int ret = ERROR_SUCCESS;
  825 +
  826 + SrsConfDirective* old_root = root;
  827 + SrsAutoFree(SrsConfDirective, old_root);
  828 +
  829 + root = conf->root;
  830 + conf->root = NULL;
  831 +
  832 + // merge config.
  833 + std::vector<ISrsReloadHandler*>::iterator it;
  834 +
  835 + // never support reload:
  836 + // daemon
  837 + //
  838 + // always support reload without additional code:
  839 + // chunk_size, ff_log_dir,
  840 + // bandcheck, http_hooks, heartbeat,
  841 + // token_traverse, debug_srs_upnode,
  842 + // security
  843 +
  844 + // merge config: max_connections
  845 + if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) {
  846 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  847 + ISrsReloadHandler* subscribe = *it;
  848 + if ((ret = subscribe->on_reload_max_conns()) != ERROR_SUCCESS) {
  849 + srs_error("notify subscribes reload max_connections failed. ret=%d", ret);
  850 + return ret;
  851 + }
  852 + }
  853 + srs_trace("reload max_connections success.");
  854 + }
  855 +
  856 + // merge config: listen
  857 + if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) {
  858 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  859 + ISrsReloadHandler* subscribe = *it;
  860 + if ((ret = subscribe->on_reload_listen()) != ERROR_SUCCESS) {
  861 + srs_error("notify subscribes reload listen failed. ret=%d", ret);
  862 + return ret;
  863 + }
  864 + }
  865 + srs_trace("reload listen success.");
  866 + }
  867 +
  868 + // merge config: pid
  869 + if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {
  870 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  871 + ISrsReloadHandler* subscribe = *it;
  872 + if ((ret = subscribe->on_reload_pid()) != ERROR_SUCCESS) {
  873 + srs_error("notify subscribes reload pid failed. ret=%d", ret);
  874 + return ret;
  875 + }
  876 + }
  877 + srs_trace("reload pid success.");
  878 + }
  879 +
  880 + // merge config: srs_log_tank
  881 + if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) {
  882 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  883 + ISrsReloadHandler* subscribe = *it;
  884 + if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) {
  885 + srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret);
  886 + return ret;
  887 + }
  888 + }
  889 + srs_trace("reload srs_log_tank success.");
  890 + }
  891 +
  892 + // merge config: srs_log_level
  893 + if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) {
  894 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  895 + ISrsReloadHandler* subscribe = *it;
  896 + if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) {
  897 + srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret);
  898 + return ret;
  899 + }
  900 + }
  901 + srs_trace("reload srs_log_level success.");
  902 + }
  903 +
  904 + // merge config: srs_log_file
  905 + if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) {
  906 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  907 + ISrsReloadHandler* subscribe = *it;
  908 + if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) {
  909 + srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret);
  910 + return ret;
  911 + }
  912 + }
  913 + srs_trace("reload srs_log_file success.");
  914 + }
  915 +
  916 + // merge config: pithy_print_ms
  917 + if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) {
  918 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  919 + ISrsReloadHandler* subscribe = *it;
  920 + if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) {
  921 + srs_error("notify subscribes pithy_print_ms listen failed. ret=%d", ret);
  922 + return ret;
  923 + }
  924 + }
  925 + srs_trace("reload pithy_print_ms success.");
  926 + }
  927 +
  928 + // merge config: http_api
  929 + if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) {
  930 + return ret;
  931 + }
  932 +
  933 + // merge config: http_stream
  934 + if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) {
  935 + return ret;
  936 + }
  937 +
  938 + // TODO: FIXME: support reload stream_caster.
  939 +
  940 + // merge config: vhost
  941 + if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) {
  942 + return ret;
  943 + }
  944 +
  945 + return ret;
  946 +}
  947 +
  948 +int SrsConfig::reload_http_api(SrsConfDirective* old_root)
  949 +{
  950 + int ret = ERROR_SUCCESS;
  951 +
  952 + // merge config.
  953 + std::vector<ISrsReloadHandler*>::iterator it;
  954 +
  955 + // state graph
  956 + // old_http_api new_http_api
  957 + // DISABLED => ENABLED
  958 + // ENABLED => DISABLED
  959 + // ENABLED => ENABLED (modified)
  960 +
  961 + SrsConfDirective* new_http_api = root->get("http_api");
  962 + SrsConfDirective* old_http_api = old_root->get("http_api");
  963 +
  964 + // DISABLED => ENABLED
  965 + if (!get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)) {
  966 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  967 + ISrsReloadHandler* subscribe = *it;
  968 + if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
  969 + srs_error("notify subscribes http_api disabled=>enabled failed. ret=%d", ret);
1009 return ret; 970 return ret;
1010 } 971 }
1011 } 972 }
1012 - srs_trace("vhost %s reload chunk_size success.", vhost.c_str()); 973 + srs_trace("reload disabled=>enabled http_api success.");
  974 +
  975 + return ret;
1013 } 976 }
1014 - // mw, only one per vhost  
1015 - if (!srs_directive_equals(new_vhost->get("mw_latency"), old_vhost->get("mw_latency"))) { 977 +
  978 + // ENABLED => DISABLED
  979 + if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) {
1016 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 980 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
1017 ISrsReloadHandler* subscribe = *it; 981 ISrsReloadHandler* subscribe = *it;
1018 - if ((ret = subscribe->on_reload_vhost_mw(vhost)) != ERROR_SUCCESS) {  
1019 - srs_error("vhost %s notify subscribes mw failed. ret=%d", vhost.c_str(), ret); 982 + if ((ret = subscribe->on_reload_http_api_disabled()) != ERROR_SUCCESS) {
  983 + srs_error("notify subscribes http_api enabled=>disabled failed. ret=%d", ret);
1020 return ret; 984 return ret;
1021 } 985 }
1022 } 986 }
1023 - srs_trace("vhost %s reload mw success.", vhost.c_str()); 987 + srs_trace("reload enabled=>disabled http_api success.");
  988 +
  989 + return ret;
1024 } 990 }
1025 - // min_latency, only one per vhost  
1026 - if (!srs_directive_equals(new_vhost->get("min_latency"), old_vhost->get("min_latency"))) { 991 +
  992 + // ENABLED => ENABLED (modified)
  993 + if (get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)
  994 + && !srs_directive_equals(old_http_api, new_http_api)
  995 + ) {
1027 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 996 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
1028 ISrsReloadHandler* subscribe = *it; 997 ISrsReloadHandler* subscribe = *it;
1029 - if ((ret = subscribe->on_reload_vhost_realtime(vhost)) != ERROR_SUCCESS) {  
1030 - srs_error("vhost %s notify subscribes min_latency failed. ret=%d", vhost.c_str(), ret); 998 + if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
  999 + srs_error("notify subscribes http_api enabled modified failed. ret=%d", ret);
1031 return ret; 1000 return ret;
1032 } 1001 }
1033 } 1002 }
1034 - srs_trace("vhost %s reload min_latency success.", vhost.c_str());  
1035 - }  
1036 - // http, only one per vhost.  
1037 - if (!srs_directive_equals(new_vhost->get("http"), old_vhost->get("http"))) {  
1038 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
1039 - ISrsReloadHandler* subscribe = *it;  
1040 - if ((ret = subscribe->on_reload_vhost_http_updated()) != ERROR_SUCCESS) {  
1041 - srs_error("vhost %s notify subscribes http failed. ret=%d", vhost.c_str(), ret); 1003 + srs_trace("reload enabled modified http_api success.");
  1004 +
1042 return ret; 1005 return ret;
1043 } 1006 }
  1007 +
  1008 + srs_trace("reload http_api not changed success.");
  1009 +
  1010 + return ret;
  1011 +}
  1012 +
  1013 +int SrsConfig::reload_http_stream(SrsConfDirective* old_root)
  1014 +{
  1015 + int ret = ERROR_SUCCESS;
  1016 +
  1017 + // merge config.
  1018 + std::vector<ISrsReloadHandler*>::iterator it;
  1019 +
  1020 + // state graph
  1021 + // old_http_stream new_http_stream
  1022 + // DISABLED => ENABLED
  1023 + // ENABLED => DISABLED
  1024 + // ENABLED => ENABLED (modified)
  1025 +
  1026 + SrsConfDirective* new_http_stream = root->get("http_stream");
  1027 + // http_stream rename to http_server in SRS2.
  1028 + if (!new_http_stream) {
  1029 + new_http_stream = root->get("http_server");
1044 } 1030 }
1045 - srs_trace("vhost %s reload http success.", vhost.c_str()); 1031 +
  1032 + SrsConfDirective* old_http_stream = old_root->get("http_stream");
  1033 + // http_stream rename to http_server in SRS2.
  1034 + if (!old_http_stream) {
  1035 + old_http_stream = root->get("http_server");
1046 } 1036 }
1047 - // http_static, only one per vhost.  
1048 - // @remark, http_static introduced as alias of http.  
1049 - if (!srs_directive_equals(new_vhost->get("http_static"), old_vhost->get("http_static"))) { 1037 +
  1038 + // DISABLED => ENABLED
  1039 + if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) {
1050 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 1040 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
1051 ISrsReloadHandler* subscribe = *it; 1041 ISrsReloadHandler* subscribe = *it;
1052 - if ((ret = subscribe->on_reload_vhost_http_updated()) != ERROR_SUCCESS) {  
1053 - srs_error("vhost %s notify subscribes http_static failed. ret=%d", vhost.c_str(), ret); 1042 + if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) {
  1043 + srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret);
1054 return ret; 1044 return ret;
1055 } 1045 }
1056 } 1046 }
1057 - srs_trace("vhost %s reload http_static success.", vhost.c_str()); 1047 + srs_trace("reload disabled=>enabled http_stream success.");
  1048 +
  1049 + return ret;
1058 } 1050 }
1059 - // http_remux, only one per vhost.  
1060 - if (!srs_directive_equals(new_vhost->get("http_remux"), old_vhost->get("http_remux"))) { 1051 +
  1052 + // ENABLED => DISABLED
  1053 + if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) {
1061 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 1054 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
1062 ISrsReloadHandler* subscribe = *it; 1055 ISrsReloadHandler* subscribe = *it;
1063 - if ((ret = subscribe->on_reload_vhost_http_remux_updated(vhost)) != ERROR_SUCCESS) {  
1064 - srs_error("vhost %s notify subscribes http_remux failed. ret=%d", vhost.c_str(), ret); 1056 + if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) {
  1057 + srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret);
1065 return ret; 1058 return ret;
1066 } 1059 }
1067 } 1060 }
1068 - srs_trace("vhost %s reload http_remux success.", vhost.c_str());  
1069 - }  
1070 - // transcode, many per vhost.  
1071 - if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) { 1061 + srs_trace("reload enabled=>disabled http_stream success.");
  1062 +
1072 return ret; 1063 return ret;
1073 } 1064 }
1074 - // ingest, many per vhost.  
1075 - if ((ret = reload_ingest(new_vhost, old_vhost)) != ERROR_SUCCESS) { 1065 +
  1066 + // ENABLED => ENABLED (modified)
  1067 + if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)
  1068 + && !srs_directive_equals(old_http_stream, new_http_stream)
  1069 + ) {
  1070 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  1071 + ISrsReloadHandler* subscribe = *it;
  1072 + if ((ret = subscribe->on_reload_http_stream_updated()) != ERROR_SUCCESS) {
  1073 + srs_error("notify subscribes http_stream enabled modified failed. ret=%d", ret);
1076 return ret; 1074 return ret;
1077 } 1075 }
1078 - continue;  
1079 } 1076 }
1080 - srs_trace("ignore reload vhost, enabled old: %d, new: %d",  
1081 - get_vhost_enabled(old_vhost), get_vhost_enabled(new_vhost)); 1077 + srs_trace("reload enabled modified http_stream success.");
  1078 +
  1079 + return ret;
1082 } 1080 }
1083 1081
  1082 + srs_trace("reload http_stream not changed success.");
  1083 +
1084 return ret; 1084 return ret;
1085 } 1085 }
1086 1086
@@ -1482,9 +1482,6 @@ int SrsConfig::check_config() @@ -1482,9 +1482,6 @@ int SrsConfig::check_config()
1482 1482
1483 srs_trace("srs checking config..."); 1483 srs_trace("srs checking config...");
1484 1484
1485 - vector<SrsConfDirective*> vhosts = get_vhosts();  
1486 - vector<SrsConfDirective*> stream_casters = get_stream_casters();  
1487 -  
1488 //////////////////////////////////////////////////////////////////////// 1485 ////////////////////////////////////////////////////////////////////////
1489 // check empty 1486 // check empty
1490 //////////////////////////////////////////////////////////////////////// 1487 ////////////////////////////////////////////////////////////////////////
@@ -1508,56 +1505,220 @@ int SrsConfig::check_config() @@ -1508,56 +1505,220 @@ int SrsConfig::check_config()
1508 && n != "utc_time" 1505 && n != "utc_time"
1509 ) { 1506 ) {
1510 ret = ERROR_SYSTEM_CONFIG_INVALID; 1507 ret = ERROR_SYSTEM_CONFIG_INVALID;
1511 - srs_error("unsupported directive %s, ret=%d", n.c_str(), ret); 1508 + srs_error("unsupported directive %s, ret=%d", n.c_str(), ret);
  1509 + return ret;
  1510 + }
  1511 + }
  1512 + if (true) {
  1513 + SrsConfDirective* conf = get_http_api();
  1514 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1515 + string n = conf->at(i)->name;
  1516 + if (n != "enabled" && n != "listen" && n != "crossdomain") {
  1517 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1518 + srs_error("unsupported http_api directive %s, ret=%d", n.c_str(), ret);
  1519 + return ret;
  1520 + }
  1521 + }
  1522 + }
  1523 + if (true) {
  1524 + SrsConfDirective* conf = get_http_stream();
  1525 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1526 + string n = conf->at(i)->name;
  1527 + if (n != "enabled" && n != "listen" && n != "dir") {
  1528 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1529 + srs_error("unsupported http_stream directive %s, ret=%d", n.c_str(), ret);
  1530 + return ret;
  1531 + }
  1532 + }
  1533 + }
  1534 + if (true) {
  1535 + SrsConfDirective* conf = get_heartbeart();
  1536 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1537 + string n = conf->at(i)->name;
  1538 + if (n != "enabled" && n != "interval" && n != "url"
  1539 + && n != "device_id" && n != "summaries"
  1540 + ) {
  1541 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1542 + srs_error("unsupported heartbeat directive %s, ret=%d", n.c_str(), ret);
  1543 + return ret;
  1544 + }
  1545 + }
  1546 + }
  1547 + if (true) {
  1548 + SrsConfDirective* conf = get_stats();
  1549 + for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
  1550 + string n = conf->at(i)->name;
  1551 + if (n != "network" && n != "disk") {
  1552 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1553 + srs_error("unsupported stats directive %s, ret=%d", n.c_str(), ret);
  1554 + return ret;
  1555 + }
  1556 + }
  1557 + }
  1558 +
  1559 +
  1560 + ////////////////////////////////////////////////////////////////////////
  1561 + // check listen for rtmp.
  1562 + ////////////////////////////////////////////////////////////////////////
  1563 + if (true) {
  1564 + vector<string> listens = get_listens();
  1565 + if (listens.size() <= 0) {
  1566 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1567 + srs_error("directive \"listen\" is empty, ret=%d", ret);
  1568 + return ret;
  1569 + }
  1570 + for (int i = 0; i < (int)listens.size(); i++) {
  1571 + string port = listens[i];
  1572 + if (port.empty() || ::atoi(port.c_str()) <= 0) {
  1573 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1574 + srs_error("directive listen invalid, port=%s, ret=%d", port.c_str(), ret);
  1575 + return ret;
  1576 + }
  1577 + }
  1578 + }
  1579 +
  1580 + ////////////////////////////////////////////////////////////////////////
  1581 + // check max connections
  1582 + ////////////////////////////////////////////////////////////////////////
  1583 + if (get_max_connections() <= 0) {
  1584 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1585 + srs_error("directive max_connections invalid, max_connections=%d, ret=%d", get_max_connections(), ret);
  1586 + return ret;
  1587 + }
  1588 +
  1589 + // check max connections of system limits
  1590 + if (true) {
  1591 + int nb_consumed_fds = (int)get_listens().size();
  1592 + if (!get_http_api_listen().empty()) {
  1593 + nb_consumed_fds++;
  1594 + }
  1595 + if (!get_http_stream_listen().empty()) {
  1596 + nb_consumed_fds++;
  1597 + }
  1598 + if (get_log_tank_file()) {
  1599 + nb_consumed_fds++;
  1600 + }
  1601 + // 0, 1, 2 for stdin, stdout and stderr.
  1602 + nb_consumed_fds += 3;
  1603 +
  1604 + int nb_connections = get_max_connections();
  1605 + int nb_total = nb_connections + nb_consumed_fds;
  1606 +
  1607 + int max_open_files = (int)sysconf(_SC_OPEN_MAX);
  1608 + int nb_canbe = max_open_files - nb_consumed_fds - 1;
  1609 +
  1610 + // for each play connections, we open a pipe(2fds) to convert SrsConsumver to io,
  1611 + // refine performance, @see: https://github.com/simple-rtmp-server/srs/issues/194
  1612 + if (nb_total >= max_open_files) {
  1613 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1614 + srs_error("invalid max_connections=%d, required=%d, system limit to %d, "
  1615 + "total=%d(max_connections=%d, nb_consumed_fds=%d), ret=%d. "
  1616 + "you can change max_connections from %d to %d, or "
  1617 + "you can login as root and set the limit: ulimit -HSn %d",
  1618 + nb_connections, nb_total + 1, max_open_files,
  1619 + nb_total, nb_connections, nb_consumed_fds,
  1620 + ret, nb_connections, nb_canbe, nb_total + 1);
  1621 + return ret;
  1622 + }
  1623 + }
  1624 +
  1625 + ////////////////////////////////////////////////////////////////////////
  1626 + // check heartbeat
  1627 + ////////////////////////////////////////////////////////////////////////
  1628 + if (get_heartbeat_interval() <= 0) {
  1629 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1630 + srs_error("directive heartbeat interval invalid, interval=%"PRId64", ret=%d",
  1631 + get_heartbeat_interval(), ret);
  1632 + return ret;
  1633 + }
  1634 +
  1635 + ////////////////////////////////////////////////////////////////////////
  1636 + // check stats
  1637 + ////////////////////////////////////////////////////////////////////////
  1638 + if (get_stats_network() < 0) {
  1639 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1640 + srs_error("directive stats network invalid, network=%d, ret=%d",
  1641 + get_stats_network(), ret);
1512 return ret; 1642 return ret;
1513 } 1643 }
1514 - }  
1515 if (true) { 1644 if (true) {
1516 - SrsConfDirective* conf = get_http_api();  
1517 - for (int i = 0; conf && i < (int)conf->directives.size(); i++) {  
1518 - string n = conf->at(i)->name;  
1519 - if (n != "enabled" && n != "listen" && n != "crossdomain") { 1645 + vector<std::string> ips = srs_get_local_ipv4_ips();
  1646 + int index = get_stats_network();
  1647 + if (index >= (int)ips.size()) {
1520 ret = ERROR_SYSTEM_CONFIG_INVALID; 1648 ret = ERROR_SYSTEM_CONFIG_INVALID;
1521 - srs_error("unsupported http_api directive %s, ret=%d", n.c_str(), ret); 1649 + srs_error("stats network invalid, total local ip count=%d, index=%d, ret=%d",
  1650 + (int)ips.size(), index, ret);
1522 return ret; 1651 return ret;
1523 } 1652 }
1524 - } 1653 + srs_warn("stats network use index=%d, ip=%s", index, ips.at(index).c_str());
1525 } 1654 }
1526 if (true) { 1655 if (true) {
1527 - SrsConfDirective* conf = get_http_stream();  
1528 - for (int i = 0; conf && i < (int)conf->directives.size(); i++) {  
1529 - string n = conf->at(i)->name;  
1530 - if (n != "enabled" && n != "listen" && n != "dir") {  
1531 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1532 - srs_error("unsupported http_stream directive %s, ret=%d", n.c_str(), ret);  
1533 - return ret; 1656 + SrsConfDirective* conf = get_stats_disk_device();
  1657 + if (conf == NULL || (int)conf->args.size() <= 0) {
  1658 + srs_warn("stats disk not configed, disk iops disabled.");
  1659 + } else {
  1660 + string disks;
  1661 + for (int i = 0; i < (int)conf->args.size(); i++) {
  1662 + disks += conf->args.at(i);
  1663 + disks += " ";
1534 } 1664 }
  1665 + srs_warn("stats disk list: %s", disks.c_str());
1535 } 1666 }
1536 } 1667 }
1537 - if (true) {  
1538 - SrsConfDirective* conf = get_heartbeart();  
1539 - for (int i = 0; conf && i < (int)conf->directives.size(); i++) {  
1540 - string n = conf->at(i)->name;  
1541 - if (n != "enabled" && n != "interval" && n != "url"  
1542 - && n != "device_id" && n != "summaries"  
1543 - ) { 1668 +
  1669 + ////////////////////////////////////////////////////////////////////////
  1670 + // check http api
  1671 + ////////////////////////////////////////////////////////////////////////
  1672 + if (get_http_api_listen().empty()) {
1544 ret = ERROR_SYSTEM_CONFIG_INVALID; 1673 ret = ERROR_SYSTEM_CONFIG_INVALID;
1545 - srs_error("unsupported heartbeat directive %s, ret=%d", n.c_str(), ret); 1674 + srs_error("directive http_api listen invalid, listen=%s, ret=%d",
  1675 + get_http_api_listen().c_str(), ret);
1546 return ret; 1676 return ret;
1547 } 1677 }
  1678 +
  1679 + ////////////////////////////////////////////////////////////////////////
  1680 + // check http stream
  1681 + ////////////////////////////////////////////////////////////////////////
  1682 + if (get_http_stream_listen().empty()) {
  1683 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1684 + srs_error("directive http_stream listen invalid, listen=%s, ret=%d",
  1685 + get_http_stream_listen().c_str(), ret);
  1686 + return ret;
1548 } 1687 }
1549 - } 1688 + ////////////////////////////////////////////////////////////////////////
  1689 + // check log name and level
  1690 + ////////////////////////////////////////////////////////////////////////
1550 if (true) { 1691 if (true) {
1551 - SrsConfDirective* conf = get_stats();  
1552 - for (int i = 0; conf && i < (int)conf->directives.size(); i++) {  
1553 - string n = conf->at(i)->name;  
1554 - if (n != "network" && n != "disk") { 1692 + std::string log_filename = this->get_log_file();
  1693 + if (get_log_tank_file() && log_filename.empty()) {
1555 ret = ERROR_SYSTEM_CONFIG_INVALID; 1694 ret = ERROR_SYSTEM_CONFIG_INVALID;
1556 - srs_error("unsupported stats directive %s, ret=%d", n.c_str(), ret); 1695 + srs_error("must specifies the file to write log to. ret=%d", ret);
1557 return ret; 1696 return ret;
1558 } 1697 }
  1698 + if (get_log_tank_file()) {
  1699 + srs_trace("write log to file %s", log_filename.c_str());
  1700 + srs_trace("you can: tailf %s", log_filename.c_str());
  1701 + srs_trace("@see: %s", SRS_WIKI_URL_LOG);
  1702 + } else {
  1703 + srs_trace("write log to console");
  1704 + }
  1705 + }
  1706 +
  1707 + ////////////////////////////////////////////////////////////////////////
  1708 + // check features
  1709 + ////////////////////////////////////////////////////////////////////////
  1710 +#ifndef SRS_AUTO_HTTP_SERVER
  1711 + if (get_http_stream_enabled()) {
  1712 + srs_warn("http_stream is disabled by configure");
1559 } 1713 }
  1714 +#endif
  1715 +#ifndef SRS_AUTO_HTTP_API
  1716 + if (get_http_api_enabled()) {
  1717 + srs_warn("http_api is disabled by configure");
1560 } 1718 }
  1719 +#endif
  1720 +
  1721 + vector<SrsConfDirective*> stream_casters = get_stream_casters();
1561 for (int n = 0; n < (int)stream_casters.size(); n++) { 1722 for (int n = 0; n < (int)stream_casters.size(); n++) {
1562 SrsConfDirective* stream_caster = stream_casters[n]; 1723 SrsConfDirective* stream_caster = stream_casters[n];
1563 for (int i = 0; stream_caster && i < (int)stream_caster->directives.size(); i++) { 1724 for (int i = 0; stream_caster && i < (int)stream_caster->directives.size(); i++) {
@@ -1572,6 +1733,9 @@ int SrsConfig::check_config() @@ -1572,6 +1733,9 @@ int SrsConfig::check_config()
1572 } 1733 }
1573 } 1734 }
1574 } 1735 }
  1736 +
  1737 + vector<SrsConfDirective*> vhosts;
  1738 + get_vhosts(vhosts);
1575 for (int n = 0; n < (int)vhosts.size(); n++) { 1739 for (int n = 0; n < (int)vhosts.size(); n++) {
1576 SrsConfDirective* vhost = vhosts[n]; 1740 SrsConfDirective* vhost = vhosts[n];
1577 for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) { 1741 for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) {
@@ -1754,135 +1918,6 @@ int SrsConfig::check_config() @@ -1754,135 +1918,6 @@ int SrsConfig::check_config()
1754 } 1918 }
1755 1919
1756 //////////////////////////////////////////////////////////////////////// 1920 ////////////////////////////////////////////////////////////////////////
1757 - // check listen for rtmp.  
1758 - ////////////////////////////////////////////////////////////////////////  
1759 - if (true) {  
1760 - vector<string> listens = get_listens();  
1761 - if (listens.size() <= 0) {  
1762 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1763 - srs_error("directive \"listen\" is empty, ret=%d", ret);  
1764 - return ret;  
1765 - }  
1766 - for (int i = 0; i < (int)listens.size(); i++) {  
1767 - string port = listens[i];  
1768 - if (port.empty() || ::atoi(port.c_str()) <= 0) {  
1769 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1770 - srs_error("directive listen invalid, port=%s, ret=%d", port.c_str(), ret);  
1771 - return ret;  
1772 - }  
1773 - }  
1774 - }  
1775 -  
1776 - ////////////////////////////////////////////////////////////////////////  
1777 - // check max connections  
1778 - ////////////////////////////////////////////////////////////////////////  
1779 - if (get_max_connections() <= 0) {  
1780 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1781 - srs_error("directive max_connections invalid, max_connections=%d, ret=%d", get_max_connections(), ret);  
1782 - return ret;  
1783 - }  
1784 -  
1785 - // check max connections of system limits  
1786 - if (true) {  
1787 - int nb_consumed_fds = (int)get_listens().size();  
1788 - if (!get_http_api_listen().empty()) {  
1789 - nb_consumed_fds++;  
1790 - }  
1791 - if (!get_http_stream_listen().empty()) {  
1792 - nb_consumed_fds++;  
1793 - }  
1794 - if (get_log_tank_file()) {  
1795 - nb_consumed_fds++;  
1796 - }  
1797 - // 0, 1, 2 for stdin, stdout and stderr.  
1798 - nb_consumed_fds += 3;  
1799 -  
1800 - int nb_connections = get_max_connections();  
1801 - int nb_total = nb_connections + nb_consumed_fds;  
1802 -  
1803 - int max_open_files = (int)sysconf(_SC_OPEN_MAX);  
1804 - int nb_canbe = max_open_files - nb_consumed_fds - 1;  
1805 -  
1806 - // for each play connections, we open a pipe(2fds) to convert SrsConsumver to io,  
1807 - // refine performance, @see: https://github.com/simple-rtmp-server/srs/issues/194  
1808 - if (nb_total >= max_open_files) {  
1809 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1810 - srs_error("invalid max_connections=%d, required=%d, system limit to %d, "  
1811 - "total=%d(max_connections=%d, nb_consumed_fds=%d), ret=%d. "  
1812 - "you can change max_connections from %d to %d, or "  
1813 - "you can login as root and set the limit: ulimit -HSn %d",  
1814 - nb_connections, nb_total + 1, max_open_files,  
1815 - nb_total, nb_connections, nb_consumed_fds,  
1816 - ret, nb_connections, nb_canbe, nb_total + 1);  
1817 - return ret;  
1818 - }  
1819 - }  
1820 -  
1821 - ////////////////////////////////////////////////////////////////////////  
1822 - // check heartbeat  
1823 - ////////////////////////////////////////////////////////////////////////  
1824 - if (get_heartbeat_interval() <= 0) {  
1825 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1826 - srs_error("directive heartbeat interval invalid, interval=%"PRId64", ret=%d",  
1827 - get_heartbeat_interval(), ret);  
1828 - return ret;  
1829 - }  
1830 -  
1831 - ////////////////////////////////////////////////////////////////////////  
1832 - // check stats  
1833 - ////////////////////////////////////////////////////////////////////////  
1834 - if (get_stats_network() < 0) {  
1835 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1836 - srs_error("directive stats network invalid, network=%d, ret=%d",  
1837 - get_stats_network(), ret);  
1838 - return ret;  
1839 - }  
1840 - if (true) {  
1841 - vector<std::string> ips = srs_get_local_ipv4_ips();  
1842 - int index = get_stats_network();  
1843 - if (index >= (int)ips.size()) {  
1844 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1845 - srs_error("stats network invalid, total local ip count=%d, index=%d, ret=%d",  
1846 - (int)ips.size(), index, ret);  
1847 - return ret;  
1848 - }  
1849 - srs_warn("stats network use index=%d, ip=%s", index, ips.at(index).c_str());  
1850 - }  
1851 - if (true) {  
1852 - SrsConfDirective* conf = get_stats_disk_device();  
1853 - if (conf == NULL || (int)conf->args.size() <= 0) {  
1854 - srs_warn("stats disk not configed, disk iops disabled.");  
1855 - } else {  
1856 - string disks;  
1857 - for (int i = 0; i < (int)conf->args.size(); i++) {  
1858 - disks += conf->args.at(i);  
1859 - disks += " ";  
1860 - }  
1861 - srs_warn("stats disk list: %s", disks.c_str());  
1862 - }  
1863 - }  
1864 -  
1865 - ////////////////////////////////////////////////////////////////////////  
1866 - // check http api  
1867 - ////////////////////////////////////////////////////////////////////////  
1868 - if (get_http_api_listen().empty()) {  
1869 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1870 - srs_error("directive http_api listen invalid, listen=%s, ret=%d",  
1871 - get_http_api_listen().c_str(), ret);  
1872 - return ret;  
1873 - }  
1874 -  
1875 - ////////////////////////////////////////////////////////////////////////  
1876 - // check http stream  
1877 - ////////////////////////////////////////////////////////////////////////  
1878 - if (get_http_stream_listen().empty()) {  
1879 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1880 - srs_error("directive http_stream listen invalid, listen=%s, ret=%d",  
1881 - get_http_stream_listen().c_str(), ret);  
1882 - return ret;  
1883 - }  
1884 -  
1885 - ////////////////////////////////////////////////////////////////////////  
1886 // check chunk size 1921 // check chunk size
1887 //////////////////////////////////////////////////////////////////////// 1922 ////////////////////////////////////////////////////////////////////////
1888 if (get_global_chunk_size() < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE 1923 if (get_global_chunk_size() < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE
@@ -1906,39 +1941,6 @@ int SrsConfig::check_config() @@ -1906,39 +1941,6 @@ int SrsConfig::check_config()
1906 return ret; 1941 return ret;
1907 } 1942 }
1908 } 1943 }
1909 -  
1910 - ////////////////////////////////////////////////////////////////////////  
1911 - // check log name and level  
1912 - ////////////////////////////////////////////////////////////////////////  
1913 - if (true) {  
1914 - std::string log_filename = this->get_log_file();  
1915 - if (get_log_tank_file() && log_filename.empty()) {  
1916 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1917 - srs_error("must specifies the file to write log to. ret=%d", ret);  
1918 - return ret;  
1919 - }  
1920 - if (get_log_tank_file()) {  
1921 - srs_trace("write log to file %s", log_filename.c_str());  
1922 - srs_trace("you can: tailf %s", log_filename.c_str());  
1923 - srs_trace("@see: %s", SRS_WIKI_URL_LOG);  
1924 - } else {  
1925 - srs_trace("write log to console");  
1926 - }  
1927 - }  
1928 -  
1929 - ////////////////////////////////////////////////////////////////////////  
1930 - // check features  
1931 - ////////////////////////////////////////////////////////////////////////  
1932 -#ifndef SRS_AUTO_HTTP_SERVER  
1933 - if (get_http_stream_enabled()) {  
1934 - srs_warn("http_stream is disabled by configure");  
1935 - }  
1936 -#endif  
1937 -#ifndef SRS_AUTO_HTTP_API  
1938 - if (get_http_api_enabled()) {  
1939 - srs_warn("http_api is disabled by configure");  
1940 - }  
1941 -#endif  
1942 for (int i = 0; i < (int)vhosts.size(); i++) { 1944 for (int i = 0; i < (int)vhosts.size(); i++) {
1943 SrsConfDirective* vhost = vhosts[i]; 1945 SrsConfDirective* vhost = vhosts[i];
1944 srs_assert(vhost != NULL); 1946 srs_assert(vhost != NULL);
@@ -2207,12 +2209,10 @@ SrsConfDirective* SrsConfig::get_vhost(string vhost) @@ -2207,12 +2209,10 @@ SrsConfDirective* SrsConfig::get_vhost(string vhost)
2207 return NULL; 2209 return NULL;
2208 } 2210 }
2209 2211
2210 -vector<SrsConfDirective*> SrsConfig::get_vhosts() 2212 +void SrsConfig::get_vhosts(vector<SrsConfDirective*>& vhosts)
2211 { 2213 {
2212 srs_assert(root); 2214 srs_assert(root);
2213 2215
2214 - std::vector<SrsConfDirective*> vhosts;  
2215 -  
2216 for (int i = 0; i < (int)root->directives.size(); i++) { 2216 for (int i = 0; i < (int)root->directives.size(); i++) {
2217 SrsConfDirective* conf = root->at(i); 2217 SrsConfDirective* conf = root->at(i);
2218 2218
@@ -2222,8 +2222,6 @@ vector<SrsConfDirective*> SrsConfig::get_vhosts() @@ -2222,8 +2222,6 @@ vector<SrsConfDirective*> SrsConfig::get_vhosts()
2222 2222
2223 vhosts.push_back(conf); 2223 vhosts.push_back(conf);
2224 } 2224 }
2225 -  
2226 - return vhosts;  
2227 } 2225 }
2228 2226
2229 bool SrsConfig::get_vhost_enabled(string vhost) 2227 bool SrsConfig::get_vhost_enabled(string vhost)
@@ -253,6 +253,11 @@ public: @@ -253,6 +253,11 @@ public:
253 * @remark, user can test the config before reload it. 253 * @remark, user can test the config before reload it.
254 */ 254 */
255 virtual int reload(); 255 virtual int reload();
  256 +private:
  257 + /**
  258 + * reload the vhost section of config.
  259 + */
  260 + virtual int reload_vhost(SrsConfDirective* old_root);
256 protected: 261 protected:
257 /** 262 /**
258 * reload from the config. 263 * reload from the config.
@@ -269,10 +274,6 @@ private: @@ -269,10 +274,6 @@ private:
269 */ 274 */
270 virtual int reload_http_stream(SrsConfDirective* old_root); 275 virtual int reload_http_stream(SrsConfDirective* old_root);
271 /** 276 /**
272 - * reload the vhost section of config.  
273 - */  
274 - virtual int reload_vhost(SrsConfDirective* old_root);  
275 - /**  
276 * reload the transcode section of vhost of config. 277 * reload the transcode section of vhost of config.
277 */ 278 */
278 virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); 279 virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);
@@ -413,7 +414,7 @@ public: @@ -413,7 +414,7 @@ public:
413 /** 414 /**
414 * get all vhosts in config file. 415 * get all vhosts in config file.
415 */ 416 */
416 - virtual std::vector<SrsConfDirective*> get_vhosts(); 417 + virtual void get_vhosts(std::vector<SrsConfDirective*>& vhosts);
417 /** 418 /**
418 * whether vhost is enabled 419 * whether vhost is enabled
419 * @param vhost, the vhost name. 420 * @param vhost, the vhost name.
@@ -543,20 +543,21 @@ int SrsHttpApi::do_cycle() @@ -543,20 +543,21 @@ int SrsHttpApi::do_cycle()
543 // always free it in this scope. 543 // always free it in this scope.
544 SrsAutoFree(ISrsHttpMessage, req); 544 SrsAutoFree(ISrsHttpMessage, req);
545 545
546 - // TODO: FIXME: use the post body.  
547 - std::string res;  
548 -  
549 - // get response body.  
550 - if ((ret = req->body_read_all(res)) != ERROR_SUCCESS) {  
551 - return ret;  
552 - }  
553 -  
554 // ok, handle http request. 546 // ok, handle http request.
555 SrsHttpResponseWriter writer(&skt); 547 SrsHttpResponseWriter writer(&skt);
556 if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) { 548 if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
557 return ret; 549 return ret;
558 } 550 }
559 551
  552 + // read all rest bytes in request body.
  553 + char buf[SRS_HTTP_READ_CACHE_BYTES];
  554 + ISrsHttpResponseReader* br = req->body_reader();
  555 + while (!br->eof()) {
  556 + if ((ret = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != ERROR_SUCCESS) {
  557 + return ret;
  558 + }
  559 + }
  560 +
560 // donot keep alive, disconnect it. 561 // donot keep alive, disconnect it.
561 // @see https://github.com/simple-rtmp-server/srs/issues/399 562 // @see https://github.com/simple-rtmp-server/srs/issues/399
562 if (!req->is_keep_alive()) { 563 if (!req->is_keep_alive()) {
@@ -293,7 +293,8 @@ int SrsIngester::parse() @@ -293,7 +293,8 @@ int SrsIngester::parse()
293 int ret = ERROR_SUCCESS; 293 int ret = ERROR_SUCCESS;
294 294
295 // parse ingesters 295 // parse ingesters
296 - std::vector<SrsConfDirective*> vhosts = _srs_config->get_vhosts(); 296 + std::vector<SrsConfDirective*> vhosts;
  297 + _srs_config->get_vhosts(vhosts);
297 298
298 for (int i = 0; i < (int)vhosts.size(); i++) { 299 for (int i = 0; i < (int)vhosts.size(); i++) {
299 SrsConfDirective* vhost = vhosts[i]; 300 SrsConfDirective* vhost = vhosts[i];