mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine the config buffer.
This commit is contained in:
parent
fd58357021
commit
3dd7156f0d
4 changed files with 55 additions and 82 deletions
|
@ -3,7 +3,7 @@ simple-rtmp-server
|
||||||
|
|
||||||
srs(simple rtmp origin live server) over state-threads.<br/>
|
srs(simple rtmp origin live server) over state-threads.<br/>
|
||||||
srs is a simple, high-performance, running in single process, origin live server.<br/>
|
srs is a simple, high-performance, running in single process, origin live server.<br/>
|
||||||
srs supports rtmp, HLS, transcoding, forward, http hooks. <br/>
|
srs supports vhost, rtmp, HLS, transcoding, forward, http hooks. <br/>
|
||||||
blog: [http://blog.csdn.net/win_lin](http://blog.csdn.net/win_lin) <br/>
|
blog: [http://blog.csdn.net/win_lin](http://blog.csdn.net/win_lin) <br/>
|
||||||
see also: [https://github.com/winlinvip/simple-rtmp-server](https://github.com/winlinvip/simple-rtmp-server) <br/>
|
see also: [https://github.com/winlinvip/simple-rtmp-server](https://github.com/winlinvip/simple-rtmp-server) <br/>
|
||||||
see also: [http://winlinvip.github.io/simple-rtmp-server](http://winlinvip.github.io/simple-rtmp-server)
|
see also: [http://winlinvip.github.io/simple-rtmp-server](http://winlinvip.github.io/simple-rtmp-server)
|
||||||
|
@ -198,6 +198,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw
|
||||||
* nginx v1.5.0: 139524 lines <br/>
|
* nginx v1.5.0: 139524 lines <br/>
|
||||||
|
|
||||||
### History
|
### History
|
||||||
|
* v0.9, 2013-12-14, support reload the hls/forwarder/transcoder.
|
||||||
* v0.9, 2013-12-14, refine the thread model for the retry threads.
|
* v0.9, 2013-12-14, refine the thread model for the retry threads.
|
||||||
* v0.9, 2013-12-10, auto install depends tools/libs on centos/ubuntu.
|
* v0.9, 2013-12-10, auto install depends tools/libs on centos/ubuntu.
|
||||||
* v0.8, 2013-12-08, v0.8 released. 19186 lines.
|
* v0.8, 2013-12-08, v0.8 released. 19186 lines.
|
||||||
|
|
|
@ -58,15 +58,35 @@ bool is_common_space(char ch)
|
||||||
return (ch == ' ' || ch == '\t' || ch == CR || ch == LF);
|
return (ch == ' ' || ch == '\t' || ch == CR || ch == LF);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CONF_BUFFER_SIZE 1024 * 1024
|
class SrsFileBuffer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int fd;
|
||||||
|
// last available position.
|
||||||
|
char* last;
|
||||||
|
// end of buffer.
|
||||||
|
char* end;
|
||||||
|
public:
|
||||||
|
// start of buffer.
|
||||||
|
char* start;
|
||||||
|
// current consumed position.
|
||||||
|
char* pos;
|
||||||
|
// current parsed line.
|
||||||
|
int line;
|
||||||
|
|
||||||
|
SrsFileBuffer();
|
||||||
|
virtual ~SrsFileBuffer();
|
||||||
|
virtual int fullfill(const char* filename);
|
||||||
|
virtual bool empty();
|
||||||
|
};
|
||||||
|
|
||||||
SrsFileBuffer::SrsFileBuffer()
|
SrsFileBuffer::SrsFileBuffer()
|
||||||
{
|
{
|
||||||
fd = -1;
|
fd = -1;
|
||||||
line = 0;
|
line = 0;
|
||||||
|
|
||||||
pos = last = start = new char[CONF_BUFFER_SIZE];
|
pos = last = start = NULL;
|
||||||
end = start + CONF_BUFFER_SIZE;
|
end = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsFileBuffer::~SrsFileBuffer()
|
SrsFileBuffer::~SrsFileBuffer()
|
||||||
|
@ -77,7 +97,7 @@ SrsFileBuffer::~SrsFileBuffer()
|
||||||
srs_freepa(start);
|
srs_freepa(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsFileBuffer::open(const char* filename)
|
int SrsFileBuffer::fullfill(const char* filename)
|
||||||
{
|
{
|
||||||
assert(fd == -1);
|
assert(fd == -1);
|
||||||
|
|
||||||
|
@ -88,9 +108,29 @@ int SrsFileBuffer::open(const char* filename)
|
||||||
|
|
||||||
line = 1;
|
line = 1;
|
||||||
|
|
||||||
|
int size = FILE_SIZE(fd) - FILE_OFFSET(fd);
|
||||||
|
if (size <= 0) {
|
||||||
|
return ERROR_SYSTEM_CONFIG_EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
srs_freepa(start);
|
||||||
|
pos = last = start = new char[size];
|
||||||
|
end = start + size;
|
||||||
|
|
||||||
|
int n = read(fd, start, size);
|
||||||
|
if (n != size) {
|
||||||
|
srs_error("read file read error. expect %d, actual %d bytes.", size, n);
|
||||||
|
return ERROR_SYSTEM_CONFIG_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SrsFileBuffer::empty()
|
||||||
|
{
|
||||||
|
return pos >= end;
|
||||||
|
}
|
||||||
|
|
||||||
SrsConfDirective::SrsConfDirective()
|
SrsConfDirective::SrsConfDirective()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -156,7 +196,7 @@ int SrsConfDirective::parse(const char* filename)
|
||||||
|
|
||||||
SrsFileBuffer buffer;
|
SrsFileBuffer buffer;
|
||||||
|
|
||||||
if ((ret = buffer.open(filename)) != ERROR_SUCCESS) {
|
if ((ret = buffer.fullfill(filename)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,11 +280,15 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string>
|
||||||
bool last_space = true;
|
bool last_space = true;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if ((ret = refill_buffer(buffer, d_quoted, s_quoted, startline, pstart)) != ERROR_SUCCESS) {
|
if (buffer->empty()) {
|
||||||
|
ret = ERROR_SYSTEM_CONFIG_EOF;
|
||||||
|
|
||||||
if (!args.empty() || !last_space) {
|
if (!args.empty() || !last_space) {
|
||||||
srs_error("line %d: unexpected end of file, expecting ; or \"}\"", buffer->line);
|
srs_error("line %d: unexpected end of file, expecting ; or \"}\"", buffer->line);
|
||||||
return ERROR_SYSTEM_CONFIG_INVALID;
|
return ERROR_SYSTEM_CONFIG_INVALID;
|
||||||
}
|
}
|
||||||
|
srs_error("end of file. ret=%d", ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,59 +407,6 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string>
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsConfDirective::refill_buffer(SrsFileBuffer* buffer, bool d_quoted, bool s_quoted, int startline, char*& pstart)
|
|
||||||
{
|
|
||||||
int ret = ERROR_SUCCESS;
|
|
||||||
|
|
||||||
if (buffer->pos < buffer->last) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int size = FILE_SIZE(buffer->fd) - FILE_OFFSET(buffer->fd);
|
|
||||||
if (size > CONF_BUFFER_SIZE) {
|
|
||||||
ret = ERROR_SYSTEM_CONFIG_TOO_LARGE;
|
|
||||||
srs_error("config file too large, max=%d, actual=%d, ret=%d",
|
|
||||||
CONF_BUFFER_SIZE, size, ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size <= 0) {
|
|
||||||
return ERROR_SYSTEM_CONFIG_EOF;
|
|
||||||
}
|
|
||||||
|
|
||||||
int len = buffer->pos - buffer->start;
|
|
||||||
if (len >= CONF_BUFFER_SIZE) {
|
|
||||||
buffer->line = startline;
|
|
||||||
|
|
||||||
if (!d_quoted && !s_quoted) {
|
|
||||||
srs_error("line %d: too long parameter \"%*s...\" started",
|
|
||||||
buffer->line, 10, buffer->start);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
srs_error("line %d: too long parameter, "
|
|
||||||
"probably missing terminating '%c' character", buffer->line, d_quoted? '"':'\'');
|
|
||||||
}
|
|
||||||
return ERROR_SYSTEM_CONFIG_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len) {
|
|
||||||
memmove(buffer->start, pstart, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
size = srs_min(size, buffer->end - (buffer->start + len));
|
|
||||||
int n = read(buffer->fd, buffer->start + len, size);
|
|
||||||
if (n != size) {
|
|
||||||
srs_error("read file read error. expect %d, actual %d bytes.", size, n);
|
|
||||||
return ERROR_SYSTEM_CONFIG_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer->pos = buffer->start + len;
|
|
||||||
buffer->last = buffer->pos + n;
|
|
||||||
pstart = buffer->start;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
SrsConfig* config = new SrsConfig();
|
SrsConfig* config = new SrsConfig();
|
||||||
|
|
||||||
SrsConfig::SrsConfig()
|
SrsConfig::SrsConfig()
|
||||||
|
|
|
@ -49,24 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// in ms, for HLS aac flush the audio
|
// in ms, for HLS aac flush the audio
|
||||||
#define SRS_CONF_DEFAULT_AAC_DELAY 300
|
#define SRS_CONF_DEFAULT_AAC_DELAY 300
|
||||||
|
|
||||||
class SrsFileBuffer
|
class SrsFileBuffer;
|
||||||
{
|
|
||||||
public:
|
|
||||||
int fd;
|
|
||||||
int line;
|
|
||||||
// start of buffer.
|
|
||||||
char* start;
|
|
||||||
// end of buffer.
|
|
||||||
char* end;
|
|
||||||
// current consumed position.
|
|
||||||
char* pos;
|
|
||||||
// last available position.
|
|
||||||
char* last;
|
|
||||||
|
|
||||||
SrsFileBuffer();
|
|
||||||
virtual ~SrsFileBuffer();
|
|
||||||
virtual int open(const char* filename);
|
|
||||||
};
|
|
||||||
|
|
||||||
class SrsConfDirective
|
class SrsConfDirective
|
||||||
{
|
{
|
||||||
|
@ -89,7 +72,6 @@ public:
|
||||||
enum SrsDirectiveType{parse_file, parse_block};
|
enum SrsDirectiveType{parse_file, parse_block};
|
||||||
virtual int parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type);
|
virtual int parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type);
|
||||||
virtual int read_token(SrsFileBuffer* buffer, std::vector<std::string>& args);
|
virtual int read_token(SrsFileBuffer* buffer, std::vector<std::string>& args);
|
||||||
virtual int refill_buffer(SrsFileBuffer* buffer, bool d_quoted, bool s_quoted, int startline, char*& pstart);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -83,9 +83,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#define ERROR_SYSTEM_CONFIG_EOF 409
|
#define ERROR_SYSTEM_CONFIG_EOF 409
|
||||||
#define ERROR_SYSTEM_STREAM_BUSY 410
|
#define ERROR_SYSTEM_STREAM_BUSY 410
|
||||||
#define ERROR_SYSTEM_IP_INVALID 411
|
#define ERROR_SYSTEM_IP_INVALID 411
|
||||||
#define ERROR_SYSTEM_CONFIG_TOO_LARGE 412
|
#define ERROR_SYSTEM_FORWARD_LOOP 412
|
||||||
#define ERROR_SYSTEM_FORWARD_LOOP 413
|
#define ERROR_SYSTEM_WAITPID 413
|
||||||
#define ERROR_SYSTEM_WAITPID 414
|
|
||||||
|
|
||||||
// see librtmp.
|
// see librtmp.
|
||||||
// failed when open ssl create the dh
|
// failed when open ssl create the dh
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue