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;
@@ -1067,20 +802,285 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) @@ -1067,20 +802,285 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
1067 } 802 }
1068 srs_trace("vhost %s reload http_remux success.", vhost.c_str()); 803 srs_trace("vhost %s reload http_remux success.", vhost.c_str());
1069 } 804 }
1070 - // transcode, many per vhost.  
1071 - if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) { 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);
  970 + return ret;
  971 + }
  972 + }
  973 + srs_trace("reload disabled=>enabled http_api success.");
  974 +
  975 + return ret;
  976 + }
  977 +
  978 + // ENABLED => DISABLED
  979 + if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) {
  980 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  981 + ISrsReloadHandler* subscribe = *it;
  982 + if ((ret = subscribe->on_reload_http_api_disabled()) != ERROR_SUCCESS) {
  983 + srs_error("notify subscribes http_api enabled=>disabled failed. ret=%d", ret);
  984 + return ret;
  985 + }
  986 + }
  987 + srs_trace("reload enabled=>disabled http_api success.");
  988 +
  989 + return ret;
  990 + }
  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 + ) {
  996 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  997 + ISrsReloadHandler* subscribe = *it;
  998 + if ((ret = subscribe->on_reload_http_api_enabled()) != ERROR_SUCCESS) {
  999 + srs_error("notify subscribes http_api enabled modified failed. ret=%d", ret);
  1000 + return ret;
  1001 + }
  1002 + }
  1003 + srs_trace("reload enabled modified http_api success.");
  1004 +
  1005 + return ret;
  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");
  1030 + }
  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");
  1036 + }
  1037 +
  1038 + // DISABLED => ENABLED
  1039 + if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) {
  1040 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  1041 + ISrsReloadHandler* subscribe = *it;
  1042 + if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) {
  1043 + srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret);
  1044 + return ret;
  1045 + }
  1046 + }
  1047 + srs_trace("reload disabled=>enabled http_stream success.");
  1048 +
  1049 + return ret;
  1050 + }
  1051 +
  1052 + // ENABLED => DISABLED
  1053 + if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) {
  1054 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  1055 + ISrsReloadHandler* subscribe = *it;
  1056 + if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) {
  1057 + srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret);
1072 return ret; 1058 return ret;
1073 } 1059 }
1074 - // ingest, many per vhost.  
1075 - if ((ret = reload_ingest(new_vhost, old_vhost)) != ERROR_SUCCESS) { 1060 + }
  1061 + srs_trace("reload enabled=>disabled http_stream success.");
  1062 +
  1063 + return ret;
  1064 + }
  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
@@ -1481,9 +1481,6 @@ int SrsConfig::check_config() @@ -1481,9 +1481,6 @@ int SrsConfig::check_config()
1481 int ret = ERROR_SUCCESS; 1481 int ret = ERROR_SUCCESS;
1482 1482
1483 srs_trace("srs checking config..."); 1483 srs_trace("srs checking config...");
1484 -  
1485 - vector<SrsConfDirective*> vhosts = get_vhosts();  
1486 - vector<SrsConfDirective*> stream_casters = get_stream_casters();  
1487 1484
1488 //////////////////////////////////////////////////////////////////////// 1485 ////////////////////////////////////////////////////////////////////////
1489 // check empty 1486 // check empty
@@ -1493,71 +1490,235 @@ int SrsConfig::check_config() @@ -1493,71 +1490,235 @@ int SrsConfig::check_config()
1493 srs_error("conf is empty, ret=%d", ret); 1490 srs_error("conf is empty, ret=%d", ret);
1494 return ret; 1491 return ret;
1495 } 1492 }
1496 - 1493 +
  1494 + ////////////////////////////////////////////////////////////////////////
  1495 + // check root directives.
  1496 + ////////////////////////////////////////////////////////////////////////
  1497 + for (int i = 0; i < (int)root->directives.size(); i++) {
  1498 + SrsConfDirective* conf = root->at(i);
  1499 + std::string n = conf->name;
  1500 + if (n != "listen" && n != "pid" && n != "chunk_size" && n != "ff_log_dir"
  1501 + && n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file"
  1502 + && n != "max_connections" && n != "daemon" && n != "heartbeat"
  1503 + && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
  1504 + && n != "http_stream" && n != "http_server" && n != "stream_caster"
  1505 + && n != "utc_time"
  1506 + ) {
  1507 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  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);
  1642 + return ret;
  1643 + }
  1644 + if (true) {
  1645 + vector<std::string> ips = srs_get_local_ipv4_ips();
  1646 + int index = get_stats_network();
  1647 + if (index >= (int)ips.size()) {
  1648 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1649 + srs_error("stats network invalid, total local ip count=%d, index=%d, ret=%d",
  1650 + (int)ips.size(), index, ret);
  1651 + return ret;
  1652 + }
  1653 + srs_warn("stats network use index=%d, ip=%s", index, ips.at(index).c_str());
  1654 + }
  1655 + if (true) {
  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 += " ";
  1664 + }
  1665 + srs_warn("stats disk list: %s", disks.c_str());
  1666 + }
  1667 + }
  1668 +
  1669 + ////////////////////////////////////////////////////////////////////////
  1670 + // check http api
  1671 + ////////////////////////////////////////////////////////////////////////
  1672 + if (get_http_api_listen().empty()) {
  1673 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1674 + srs_error("directive http_api listen invalid, listen=%s, ret=%d",
  1675 + get_http_api_listen().c_str(), ret);
  1676 + return ret;
  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;
  1687 + }
1497 //////////////////////////////////////////////////////////////////////// 1688 ////////////////////////////////////////////////////////////////////////
1498 - // check root directives. 1689 + // check log name and level
1499 //////////////////////////////////////////////////////////////////////// 1690 ////////////////////////////////////////////////////////////////////////
1500 - for (int i = 0; i < (int)root->directives.size(); i++) {  
1501 - SrsConfDirective* conf = root->at(i);  
1502 - std::string n = conf->name;  
1503 - if (n != "listen" && n != "pid" && n != "chunk_size" && n != "ff_log_dir"  
1504 - && n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file"  
1505 - && n != "max_connections" && n != "daemon" && n != "heartbeat"  
1506 - && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"  
1507 - && n != "http_stream" && n != "http_server" && n != "stream_caster"  
1508 - && n != "utc_time"  
1509 - ) { 1691 + if (true) {
  1692 + std::string log_filename = this->get_log_file();
  1693 + if (get_log_tank_file() && log_filename.empty()) {
1510 ret = ERROR_SYSTEM_CONFIG_INVALID; 1694 ret = ERROR_SYSTEM_CONFIG_INVALID;
1511 - srs_error("unsupported directive %s, ret=%d", n.c_str(), ret); 1695 + srs_error("must specifies the file to write log to. ret=%d", ret);
1512 return ret; 1696 return ret;
1513 } 1697 }
1514 - }  
1515 - 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") {  
1520 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1521 - srs_error("unsupported http_api directive %s, ret=%d", n.c_str(), ret);  
1522 - return ret;  
1523 - }  
1524 - }  
1525 - }  
1526 - 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;  
1534 - } 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");
1535 } 1704 }
1536 } 1705 }
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 - ) {  
1544 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1545 - srs_error("unsupported heartbeat directive %s, ret=%d", n.c_str(), ret);  
1546 - return ret;  
1547 - }  
1548 - } 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");
1549 } 1713 }
1550 - 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") {  
1555 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1556 - srs_error("unsupported stats directive %s, ret=%d", n.c_str(), ret);  
1557 - return ret;  
1558 - }  
1559 - } 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++) {
@@ -1565,13 +1726,16 @@ int SrsConfig::check_config() @@ -1565,13 +1726,16 @@ int SrsConfig::check_config()
1565 string n = conf->name; 1726 string n = conf->name;
1566 if (n != "enabled" && n != "caster" && n != "output" 1727 if (n != "enabled" && n != "caster" && n != "output"
1567 && n != "listen" && n != "rtp_port_min" && n != "rtp_port_max" 1728 && n != "listen" && n != "rtp_port_min" && n != "rtp_port_max"
1568 - ) { 1729 + ) {
1569 ret = ERROR_SYSTEM_CONFIG_INVALID; 1730 ret = ERROR_SYSTEM_CONFIG_INVALID;
1570 srs_error("unsupported stream_caster directive %s, ret=%d", n.c_str(), ret); 1731 srs_error("unsupported stream_caster directive %s, ret=%d", n.c_str(), ret);
1571 return ret; 1732 return ret;
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++) {
@@ -1601,7 +1765,7 @@ int SrsConfig::check_config() @@ -1601,7 +1765,7 @@ int SrsConfig::check_config()
1601 string m = conf->at(j)->name.c_str(); 1765 string m = conf->at(j)->name.c_str();
1602 if (m != "enabled" && m != "dvr_path" && m != "dvr_plan" 1766 if (m != "enabled" && m != "dvr_path" && m != "dvr_plan"
1603 && m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter" 1767 && m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter"
1604 - ) { 1768 + ) {
1605 ret = ERROR_SYSTEM_CONFIG_INVALID; 1769 ret = ERROR_SYSTEM_CONFIG_INVALID;
1606 srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret); 1770 srs_error("unsupported vhost dvr directive %s, ret=%d", m.c_str(), ret);
1607 return ret; 1771 return ret;
@@ -1611,7 +1775,7 @@ int SrsConfig::check_config() @@ -1611,7 +1775,7 @@ int SrsConfig::check_config()
1611 for (int j = 0; j < (int)conf->directives.size(); j++) { 1775 for (int j = 0; j < (int)conf->directives.size(); j++) {
1612 string m = conf->at(j)->name.c_str(); 1776 string m = conf->at(j)->name.c_str();
1613 if (m != "enabled" && m != "latency" 1777 if (m != "enabled" && m != "latency"
1614 - ) { 1778 + ) {
1615 ret = ERROR_SYSTEM_CONFIG_INVALID; 1779 ret = ERROR_SYSTEM_CONFIG_INVALID;
1616 srs_error("unsupported vhost mr directive %s, ret=%d", m.c_str(), ret); 1780 srs_error("unsupported vhost mr directive %s, ret=%d", m.c_str(), ret);
1617 return ret; 1781 return ret;
@@ -1622,7 +1786,7 @@ int SrsConfig::check_config() @@ -1622,7 +1786,7 @@ int SrsConfig::check_config()
1622 string m = conf->at(j)->name.c_str(); 1786 string m = conf->at(j)->name.c_str();
1623 if (m != "enabled" && m != "input" && m != "ffmpeg" 1787 if (m != "enabled" && m != "input" && m != "ffmpeg"
1624 && m != "engine" 1788 && m != "engine"
1625 - ) { 1789 + ) {
1626 ret = ERROR_SYSTEM_CONFIG_INVALID; 1790 ret = ERROR_SYSTEM_CONFIG_INVALID;
1627 srs_error("unsupported vhost ingest directive %s, ret=%d", m.c_str(), ret); 1791 srs_error("unsupported vhost ingest directive %s, ret=%d", m.c_str(), ret);
1628 return ret; 1792 return ret;
@@ -1653,7 +1817,7 @@ int SrsConfig::check_config() @@ -1653,7 +1817,7 @@ int SrsConfig::check_config()
1653 && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" 1817 && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec"
1654 && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify" 1818 && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify"
1655 && m != "hls_wait_keyframe" && m != "hls_dispose" 1819 && m != "hls_wait_keyframe" && m != "hls_dispose"
1656 - ) { 1820 + ) {
1657 ret = ERROR_SYSTEM_CONFIG_INVALID; 1821 ret = ERROR_SYSTEM_CONFIG_INVALID;
1658 srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); 1822 srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
1659 return ret; 1823 return ret;
@@ -1665,7 +1829,7 @@ int SrsConfig::check_config() @@ -1665,7 +1829,7 @@ int SrsConfig::check_config()
1665 if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish" 1829 if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish"
1666 && m != "on_unpublish" && m != "on_play" && m != "on_stop" 1830 && m != "on_unpublish" && m != "on_play" && m != "on_stop"
1667 && m != "on_dvr" && m != "on_hls" && m != "on_hls_notify" 1831 && m != "on_dvr" && m != "on_hls" && m != "on_hls_notify"
1668 - ) { 1832 + ) {
1669 ret = ERROR_SYSTEM_CONFIG_INVALID; 1833 ret = ERROR_SYSTEM_CONFIG_INVALID;
1670 srs_error("unsupported vhost http_hooks directive %s, ret=%d", m.c_str(), ret); 1834 srs_error("unsupported vhost http_hooks directive %s, ret=%d", m.c_str(), ret);
1671 return ret; 1835 return ret;
@@ -1709,7 +1873,7 @@ int SrsConfig::check_config() @@ -1709,7 +1873,7 @@ int SrsConfig::check_config()
1709 && e != "acodec" && e != "abitrate" && e != "asample_rate" && e != "achannels" 1873 && e != "acodec" && e != "abitrate" && e != "asample_rate" && e != "achannels"
1710 && e != "aparams" && e != "output" 1874 && e != "aparams" && e != "output"
1711 && e != "iformat" && e != "oformat" 1875 && e != "iformat" && e != "oformat"
1712 - ) { 1876 + ) {
1713 ret = ERROR_SYSTEM_CONFIG_INVALID; 1877 ret = ERROR_SYSTEM_CONFIG_INVALID;
1714 srs_error("unsupported vhost transcode engine directive %s, ret=%d", e.c_str(), ret); 1878 srs_error("unsupported vhost transcode engine directive %s, ret=%d", e.c_str(), ret);
1715 return ret; 1879 return ret;
@@ -1733,19 +1897,19 @@ int SrsConfig::check_config() @@ -1733,19 +1897,19 @@ int SrsConfig::check_config()
1733 for (int i = 0; i < (int)vhosts.size(); i++) { 1897 for (int i = 0; i < (int)vhosts.size(); i++) {
1734 SrsConfDirective* vhost = vhosts[i]; 1898 SrsConfDirective* vhost = vhosts[i];
1735 std::vector<std::string> ids; 1899 std::vector<std::string> ids;
1736 - 1900 +
1737 for (int j = 0; j < (int)vhost->directives.size(); j++) { 1901 for (int j = 0; j < (int)vhost->directives.size(); j++) {
1738 SrsConfDirective* conf = vhost->at(j); 1902 SrsConfDirective* conf = vhost->at(j);
1739 if (conf->name != "ingest") { 1903 if (conf->name != "ingest") {
1740 continue; 1904 continue;
1741 } 1905 }
1742 - 1906 +
1743 std::string id = conf->arg0(); 1907 std::string id = conf->arg0();
1744 for (int k = 0; k < (int)ids.size(); k++) { 1908 for (int k = 0; k < (int)ids.size(); k++) {
1745 if (id == ids.at(k)) { 1909 if (id == ids.at(k)) {
1746 ret = ERROR_SYSTEM_CONFIG_INVALID; 1910 ret = ERROR_SYSTEM_CONFIG_INVALID;
1747 - srs_error("directive \"ingest\" id duplicated, vhost=%s, id=%s, ret=%d",  
1748 - vhost->name.c_str(), id.c_str(), ret); 1911 + srs_error("directive \"ingest\" id duplicated, vhost=%s, id=%s, ret=%d",
  1912 + vhost->name.c_str(), id.c_str(), ret);
1749 return ret; 1913 return ret;
1750 } 1914 }
1751 } 1915 }
@@ -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,23 +2209,19 @@ SrsConfDirective* SrsConfig::get_vhost(string vhost) @@ -2207,23 +2209,19 @@ 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 -  
2214 - std::vector<SrsConfDirective*> vhosts;  
2215 - 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 +
2219 if (!conf->is_vhost()) { 2219 if (!conf->is_vhost()) {
2220 continue; 2220 continue;
2221 } 2221 }
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];