正在显示
1 个修改的文件
包含
29 行增加
和
21 行删除
| @@ -61,14 +61,13 @@ bool is_common_space(char ch) | @@ -61,14 +61,13 @@ bool is_common_space(char ch) | ||
| 61 | class SrsFileBuffer | 61 | class SrsFileBuffer |
| 62 | { | 62 | { |
| 63 | private: | 63 | private: |
| 64 | - int fd; | ||
| 65 | // last available position. | 64 | // last available position. |
| 66 | char* last; | 65 | char* last; |
| 67 | // end of buffer. | 66 | // end of buffer. |
| 68 | char* end; | 67 | char* end; |
| 69 | -public: | ||
| 70 | // start of buffer. | 68 | // start of buffer. |
| 71 | char* start; | 69 | char* start; |
| 70 | +public: | ||
| 72 | // current consumed position. | 71 | // current consumed position. |
| 73 | char* pos; | 72 | char* pos; |
| 74 | // current parsed line. | 73 | // current parsed line. |
| @@ -82,7 +81,6 @@ public: | @@ -82,7 +81,6 @@ public: | ||
| 82 | 81 | ||
| 83 | SrsFileBuffer::SrsFileBuffer() | 82 | SrsFileBuffer::SrsFileBuffer() |
| 84 | { | 83 | { |
| 85 | - fd = -1; | ||
| 86 | line = 0; | 84 | line = 0; |
| 87 | 85 | ||
| 88 | pos = last = start = NULL; | 86 | pos = last = start = NULL; |
| @@ -91,39 +89,48 @@ SrsFileBuffer::SrsFileBuffer() | @@ -91,39 +89,48 @@ SrsFileBuffer::SrsFileBuffer() | ||
| 91 | 89 | ||
| 92 | SrsFileBuffer::~SrsFileBuffer() | 90 | SrsFileBuffer::~SrsFileBuffer() |
| 93 | { | 91 | { |
| 94 | - if (fd > 0) { | ||
| 95 | - close(fd); | ||
| 96 | - } | ||
| 97 | srs_freepa(start); | 92 | srs_freepa(start); |
| 98 | } | 93 | } |
| 99 | 94 | ||
| 100 | int SrsFileBuffer::fullfill(const char* filename) | 95 | int SrsFileBuffer::fullfill(const char* filename) |
| 101 | { | 96 | { |
| 102 | - assert(fd == -1); | 97 | + int ret = ERROR_SUCCESS; |
| 98 | + | ||
| 99 | + int fd = -1; | ||
| 100 | + int nread = 0; | ||
| 101 | + int filesize = 0; | ||
| 103 | 102 | ||
| 104 | if ((fd = ::open(filename, O_RDONLY, 0)) < 0) { | 103 | if ((fd = ::open(filename, O_RDONLY, 0)) < 0) { |
| 105 | - srs_error("open conf file error. errno=%d(%s)", errno, strerror(errno)); | ||
| 106 | - return ERROR_SYSTEM_CONFIG_INVALID; | 104 | + ret = ERROR_SYSTEM_CONFIG_INVALID; |
| 105 | + srs_error("open conf file error. ret=%d", ret); | ||
| 106 | + goto finish; | ||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | - line = 1; | ||
| 110 | - | ||
| 111 | - int size = FILE_SIZE(fd) - FILE_OFFSET(fd); | ||
| 112 | - if (size <= 0) { | ||
| 113 | - return ERROR_SYSTEM_CONFIG_EOF; | 109 | + if ((filesize = FILE_SIZE(fd) - FILE_OFFSET(fd)) <= 0) { |
| 110 | + ret = ERROR_SYSTEM_CONFIG_EOF; | ||
| 111 | + srs_error("read conf file error. ret=%d", ret); | ||
| 112 | + goto finish; | ||
| 114 | } | 113 | } |
| 115 | 114 | ||
| 116 | srs_freepa(start); | 115 | srs_freepa(start); |
| 117 | - pos = last = start = new char[size]; | ||
| 118 | - end = start + size; | 116 | + pos = last = start = new char[filesize]; |
| 117 | + end = start + filesize; | ||
| 119 | 118 | ||
| 120 | - int n = read(fd, start, size); | ||
| 121 | - if (n != size) { | ||
| 122 | - srs_error("read file read error. expect %d, actual %d bytes.", size, n); | ||
| 123 | - return ERROR_SYSTEM_CONFIG_INVALID; | 119 | + if ((nread = read(fd, start, filesize)) != filesize) { |
| 120 | + ret = ERROR_SYSTEM_CONFIG_INVALID; | ||
| 121 | + srs_error("read file read error. expect %d, actual %d bytes, ret=%d", | ||
| 122 | + filesize, nread, ret); | ||
| 123 | + goto finish; | ||
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | - return ERROR_SUCCESS; | 126 | + line = 1; |
| 127 | + | ||
| 128 | +finish: | ||
| 129 | + if (fd > 0) { | ||
| 130 | + ::close(fd); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + return ret; | ||
| 127 | } | 134 | } |
| 128 | 135 | ||
| 129 | bool SrsFileBuffer::empty() | 136 | bool SrsFileBuffer::empty() |
| @@ -1245,6 +1252,7 @@ int SrsConfig::parse_file(const char* filename) | @@ -1245,6 +1252,7 @@ int SrsConfig::parse_file(const char* filename) | ||
| 1245 | "directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret); | 1252 | "directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret); |
| 1246 | return ret; | 1253 | return ret; |
| 1247 | } | 1254 | } |
| 1255 | + | ||
| 1248 | // TODO: check the hls. | 1256 | // TODO: check the hls. |
| 1249 | // TODO: check other config. | 1257 | // TODO: check other config. |
| 1250 | // TODO: check hls. | 1258 | // TODO: check hls. |
-
请 注册 或 登录 后发表评论