正在显示
8 个修改的文件
包含
199 行增加
和
17 行删除
| @@ -82,7 +82,7 @@ LibSTfile="${LibSTRoot}/libst.a" | @@ -82,7 +82,7 @@ LibSTfile="${LibSTRoot}/libst.a" | ||
| 82 | MODULE_ID="CORE" | 82 | MODULE_ID="CORE" |
| 83 | MODULE_DEPENDS=() | 83 | MODULE_DEPENDS=() |
| 84 | ModuleLibIncs=(${LibSTRoot}) | 84 | ModuleLibIncs=(${LibSTRoot}) |
| 85 | -MODULE_FILES=("srs_core" "srs_core_log") | 85 | +MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" "srs_core_error") |
| 86 | MODULE_DIR="src/core" . auto/modules.sh | 86 | MODULE_DIR="src/core" . auto/modules.sh |
| 87 | CORE_OBJS="${MODULE_OBJS[@]}" | 87 | CORE_OBJS="${MODULE_OBJS[@]}" |
| 88 | 88 |
trunk/src/core/srs_core_error.cpp
0 → 100755
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#include <srs_core_error.hpp> |
trunk/src/core/srs_core_error.hpp
0 → 100755
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_CORE_ERROR_HPP | ||
| 25 | +#define SRS_CORE_ERROR_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_core_error.hpp> | ||
| 29 | +*/ | ||
| 30 | + | ||
| 31 | +#define ERROR_SUCCESS 0 | ||
| 32 | + | ||
| 33 | +#define ERROR_ST_SET_EPOLL 100 | ||
| 34 | +#define ERROR_ST_INITIALIZE 101 | ||
| 35 | + | ||
| 36 | +#endif |
| @@ -31,10 +31,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,10 +31,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | 31 | ||
| 32 | #include <st.h> | 32 | #include <st.h> |
| 33 | 33 | ||
| 34 | -ILogContext::ILogContext(){ | 34 | +ILogContext::ILogContext() |
| 35 | +{ | ||
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | -ILogContext::~ILogContext(){ | 38 | +ILogContext::~ILogContext() |
| 39 | +{ | ||
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | class LogContext : public ILogContext | 42 | class LogContext : public ILogContext |
| @@ -67,22 +69,25 @@ public: | @@ -67,22 +69,25 @@ public: | ||
| 67 | 69 | ||
| 68 | ILogContext* log_context = new LogContext(); | 70 | ILogContext* log_context = new LogContext(); |
| 69 | 71 | ||
| 70 | -LogContext::DateTime::DateTime(){ | 72 | +LogContext::DateTime::DateTime() |
| 73 | +{ | ||
| 71 | memset(time_data, 0, DATE_LEN); | 74 | memset(time_data, 0, DATE_LEN); |
| 72 | } | 75 | } |
| 73 | 76 | ||
| 74 | -LogContext::DateTime::~DateTime(){ | 77 | +LogContext::DateTime::~DateTime() |
| 78 | +{ | ||
| 75 | } | 79 | } |
| 76 | 80 | ||
| 77 | -const char* LogContext::DateTime::FormatTime(){ | 81 | +const char* LogContext::DateTime::FormatTime() |
| 82 | +{ | ||
| 78 | // clock time | 83 | // clock time |
| 79 | timeval tv; | 84 | timeval tv; |
| 80 | - if(gettimeofday(&tv, NULL) == -1){ | 85 | + if (gettimeofday(&tv, NULL) == -1) { |
| 81 | return ""; | 86 | return ""; |
| 82 | } | 87 | } |
| 83 | // to calendar time | 88 | // to calendar time |
| 84 | struct tm* tm; | 89 | struct tm* tm; |
| 85 | - if((tm = localtime(&tv.tv_sec)) == NULL){ | 90 | + if ((tm = localtime(&tv.tv_sec)) == NULL) { |
| 86 | return ""; | 91 | return ""; |
| 87 | } | 92 | } |
| 88 | 93 | ||
| @@ -95,22 +100,27 @@ const char* LogContext::DateTime::FormatTime(){ | @@ -95,22 +100,27 @@ const char* LogContext::DateTime::FormatTime(){ | ||
| 95 | return time_data; | 100 | return time_data; |
| 96 | } | 101 | } |
| 97 | 102 | ||
| 98 | -LogContext::LogContext(){ | 103 | +LogContext::LogContext() |
| 104 | +{ | ||
| 99 | } | 105 | } |
| 100 | 106 | ||
| 101 | -LogContext::~LogContext(){ | 107 | +LogContext::~LogContext() |
| 108 | +{ | ||
| 102 | } | 109 | } |
| 103 | 110 | ||
| 104 | -void LogContext::SetId(){ | ||
| 105 | - static int id = 0; | 111 | +void LogContext::SetId() |
| 112 | +{ | ||
| 113 | + static int id = 1; | ||
| 106 | cache[st_thread_self()] = id++; | 114 | cache[st_thread_self()] = id++; |
| 107 | } | 115 | } |
| 108 | 116 | ||
| 109 | -int LogContext::GetId(){ | 117 | +int LogContext::GetId() |
| 118 | +{ | ||
| 110 | return cache[st_thread_self()]; | 119 | return cache[st_thread_self()]; |
| 111 | } | 120 | } |
| 112 | 121 | ||
| 113 | -const char* LogContext::FormatTime(){ | 122 | +const char* LogContext::FormatTime() |
| 123 | +{ | ||
| 114 | return time.FormatTime(); | 124 | return time.FormatTime(); |
| 115 | } | 125 | } |
| 116 | 126 |
trunk/src/core/srs_core_server.cpp
0 → 100755
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#include <st.h> | ||
| 25 | + | ||
| 26 | +#include <srs_core_log.hpp> | ||
| 27 | +#include <srs_core_error.hpp> | ||
| 28 | + | ||
| 29 | +#include <srs_core_server.hpp> | ||
| 30 | + | ||
| 31 | +SrsServer::SrsServer() | ||
| 32 | +{ | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +SrsServer::~SrsServer() | ||
| 36 | +{ | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +int SrsServer::initialize() | ||
| 40 | +{ | ||
| 41 | + int ret = ERROR_SUCCESS; | ||
| 42 | + | ||
| 43 | + // use linux epoll. | ||
| 44 | + if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) { | ||
| 45 | + ret = ERROR_ST_SET_EPOLL; | ||
| 46 | + SrsError("st_set_eventsys use linux epoll failed. ret=%d", ret); | ||
| 47 | + return ret; | ||
| 48 | + } | ||
| 49 | + SrsInfo("st_set_eventsys use linux epoll success"); | ||
| 50 | + | ||
| 51 | + if(st_init() != 0){ | ||
| 52 | + ret = ERROR_ST_INITIALIZE; | ||
| 53 | + SrsError("st_init failed. ret=%d", ret); | ||
| 54 | + return ret; | ||
| 55 | + } | ||
| 56 | + SrsTrace("st_init success"); | ||
| 57 | + | ||
| 58 | + // set current log id. | ||
| 59 | + log_context->SetId(); | ||
| 60 | + SrsInfo("log set id success"); | ||
| 61 | + | ||
| 62 | + return ret; | ||
| 63 | +} |
trunk/src/core/srs_core_server.hpp
0 → 100755
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_CORE_SERVER_HPP | ||
| 25 | +#define SRS_CORE_SERVER_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_core_server.hpp> | ||
| 29 | +*/ | ||
| 30 | + | ||
| 31 | +class SrsServer | ||
| 32 | +{ | ||
| 33 | +public: | ||
| 34 | + SrsServer(); | ||
| 35 | + virtual ~SrsServer(); | ||
| 36 | +public: | ||
| 37 | + virtual int initialize(); | ||
| 38 | +}; | ||
| 39 | + | ||
| 40 | +#endif |
| @@ -24,12 +24,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -24,12 +24,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 24 | #include <unistd.h> | 24 | #include <unistd.h> |
| 25 | 25 | ||
| 26 | #include <srs_core_log.hpp> | 26 | #include <srs_core_log.hpp> |
| 27 | +#include <srs_core_error.hpp> | ||
| 28 | +#include <srs_core_server.hpp> | ||
| 27 | 29 | ||
| 28 | int main(int /*argc*/, char** /*argv*/){ | 30 | int main(int /*argc*/, char** /*argv*/){ |
| 29 | - log_context->SetId(); | 31 | + int ret = ERROR_SUCCESS; |
| 30 | 32 | ||
| 31 | - SrsWarn("server start."); | ||
| 32 | - SrsInfo("listen at 1935"); | 33 | + SrsServer server; |
| 34 | + | ||
| 35 | + if ((ret = server.initialize()) != ERROR_SUCCESS) { | ||
| 36 | + return ret; | ||
| 37 | + } | ||
| 33 | 38 | ||
| 34 | return 0; | 39 | return 0; |
| 35 | } | 40 | } |
| @@ -4,6 +4,10 @@ file | @@ -4,6 +4,10 @@ file | ||
| 4 | core readonly separator, | 4 | core readonly separator, |
| 5 | ..\core\srs_core.hpp, | 5 | ..\core\srs_core.hpp, |
| 6 | ..\core\srs_core.cpp, | 6 | ..\core\srs_core.cpp, |
| 7 | + ..\core\srs_core_error.hpp, | ||
| 8 | + ..\core\srs_core_error.cpp, | ||
| 9 | + ..\core\srs_core_server.hpp, | ||
| 10 | + ..\core\srs_core_server.cpp, | ||
| 7 | ..\core\srs_core_log.hpp, | 11 | ..\core\srs_core_log.hpp, |
| 8 | ..\core\srs_core_log.cpp; | 12 | ..\core\srs_core_log.cpp; |
| 9 | mainconfig | 13 | mainconfig |
-
请 注册 或 登录 后发表评论