mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 11:21:52 +00:00
init st, add error code
This commit is contained in:
parent
eb3b824e6c
commit
5b02f9c78b
8 changed files with 201 additions and 19 deletions
2
trunk/configure
vendored
2
trunk/configure
vendored
|
@ -82,7 +82,7 @@ LibSTfile="${LibSTRoot}/libst.a"
|
|||
MODULE_ID="CORE"
|
||||
MODULE_DEPENDS=()
|
||||
ModuleLibIncs=(${LibSTRoot})
|
||||
MODULE_FILES=("srs_core" "srs_core_log")
|
||||
MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" "srs_core_error")
|
||||
MODULE_DIR="src/core" . auto/modules.sh
|
||||
CORE_OBJS="${MODULE_OBJS[@]}"
|
||||
|
||||
|
|
24
trunk/src/core/srs_core_error.cpp
Executable file
24
trunk/src/core/srs_core_error.cpp
Executable file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <srs_core_error.hpp>
|
36
trunk/src/core/srs_core_error.hpp
Executable file
36
trunk/src/core/srs_core_error.hpp
Executable file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_CORE_ERROR_HPP
|
||||
#define SRS_CORE_ERROR_HPP
|
||||
|
||||
/*
|
||||
#include <srs_core_error.hpp>
|
||||
*/
|
||||
|
||||
#define ERROR_SUCCESS 0
|
||||
|
||||
#define ERROR_ST_SET_EPOLL 100
|
||||
#define ERROR_ST_INITIALIZE 101
|
||||
|
||||
#endif
|
|
@ -31,10 +31,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <st.h>
|
||||
|
||||
ILogContext::ILogContext(){
|
||||
ILogContext::ILogContext()
|
||||
{
|
||||
}
|
||||
|
||||
ILogContext::~ILogContext(){
|
||||
ILogContext::~ILogContext()
|
||||
{
|
||||
}
|
||||
|
||||
class LogContext : public ILogContext
|
||||
|
@ -67,14 +69,17 @@ public:
|
|||
|
||||
ILogContext* log_context = new LogContext();
|
||||
|
||||
LogContext::DateTime::DateTime(){
|
||||
LogContext::DateTime::DateTime()
|
||||
{
|
||||
memset(time_data, 0, DATE_LEN);
|
||||
}
|
||||
|
||||
LogContext::DateTime::~DateTime(){
|
||||
LogContext::DateTime::~DateTime()
|
||||
{
|
||||
}
|
||||
|
||||
const char* LogContext::DateTime::FormatTime(){
|
||||
const char* LogContext::DateTime::FormatTime()
|
||||
{
|
||||
// clock time
|
||||
timeval tv;
|
||||
if (gettimeofday(&tv, NULL) == -1) {
|
||||
|
@ -95,22 +100,27 @@ const char* LogContext::DateTime::FormatTime(){
|
|||
return time_data;
|
||||
}
|
||||
|
||||
LogContext::LogContext(){
|
||||
LogContext::LogContext()
|
||||
{
|
||||
}
|
||||
|
||||
LogContext::~LogContext(){
|
||||
LogContext::~LogContext()
|
||||
{
|
||||
}
|
||||
|
||||
void LogContext::SetId(){
|
||||
static int id = 0;
|
||||
void LogContext::SetId()
|
||||
{
|
||||
static int id = 1;
|
||||
cache[st_thread_self()] = id++;
|
||||
}
|
||||
|
||||
int LogContext::GetId(){
|
||||
int LogContext::GetId()
|
||||
{
|
||||
return cache[st_thread_self()];
|
||||
}
|
||||
|
||||
const char* LogContext::FormatTime(){
|
||||
const char* LogContext::FormatTime()
|
||||
{
|
||||
return time.FormatTime();
|
||||
}
|
||||
|
||||
|
|
63
trunk/src/core/srs_core_server.cpp
Executable file
63
trunk/src/core/srs_core_server.cpp
Executable file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <st.h>
|
||||
|
||||
#include <srs_core_log.hpp>
|
||||
#include <srs_core_error.hpp>
|
||||
|
||||
#include <srs_core_server.hpp>
|
||||
|
||||
SrsServer::SrsServer()
|
||||
{
|
||||
}
|
||||
|
||||
SrsServer::~SrsServer()
|
||||
{
|
||||
}
|
||||
|
||||
int SrsServer::initialize()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// use linux epoll.
|
||||
if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) {
|
||||
ret = ERROR_ST_SET_EPOLL;
|
||||
SrsError("st_set_eventsys use linux epoll failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
SrsInfo("st_set_eventsys use linux epoll success");
|
||||
|
||||
if(st_init() != 0){
|
||||
ret = ERROR_ST_INITIALIZE;
|
||||
SrsError("st_init failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
SrsTrace("st_init success");
|
||||
|
||||
// set current log id.
|
||||
log_context->SetId();
|
||||
SrsInfo("log set id success");
|
||||
|
||||
return ret;
|
||||
}
|
40
trunk/src/core/srs_core_server.hpp
Executable file
40
trunk/src/core/srs_core_server.hpp
Executable file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_CORE_SERVER_HPP
|
||||
#define SRS_CORE_SERVER_HPP
|
||||
|
||||
/*
|
||||
#include <srs_core_server.hpp>
|
||||
*/
|
||||
|
||||
class SrsServer
|
||||
{
|
||||
public:
|
||||
SrsServer();
|
||||
virtual ~SrsServer();
|
||||
public:
|
||||
virtual int initialize();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -24,12 +24,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <unistd.h>
|
||||
|
||||
#include <srs_core_log.hpp>
|
||||
#include <srs_core_error.hpp>
|
||||
#include <srs_core_server.hpp>
|
||||
|
||||
int main(int /*argc*/, char** /*argv*/){
|
||||
log_context->SetId();
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
SrsWarn("server start.");
|
||||
SrsInfo("listen at 1935");
|
||||
SrsServer server;
|
||||
|
||||
if ((ret = server.initialize()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,10 @@ file
|
|||
core readonly separator,
|
||||
..\core\srs_core.hpp,
|
||||
..\core\srs_core.cpp,
|
||||
..\core\srs_core_error.hpp,
|
||||
..\core\srs_core_error.cpp,
|
||||
..\core\srs_core_server.hpp,
|
||||
..\core\srs_core_server.cpp,
|
||||
..\core\srs_core_log.hpp,
|
||||
..\core\srs_core_log.cpp;
|
||||
mainconfig
|
||||
|
|
Loading…
Reference in a new issue