Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

缓冲输出模式的bug #47

Closed
mojinpan opened this issue Mar 30, 2019 · 1 comment
Closed

缓冲输出模式的bug #47

mojinpan opened this issue Mar 30, 2019 · 1 comment

Comments

@mojinpan
Copy link

elog_buf_output()函数有问题,输出不完整
`void elog_buf_output(const char *log, size_t size) {
size_t write_size = 0, write_index = 0;

if (!is_enabled) {
    elog_port_output(log, size);
    return;
}

//循环有什么用?每次调用此处只会被执行一次
while (true) {
if (buf_write_size + size > ELOG_BUF_OUTPUT_BUF_SIZE) {
//缓冲区满时log被拆分输出?
write_size = ELOG_BUF_OUTPUT_BUF_SIZE - buf_write_size;
memcpy(log_buf + buf_write_size, log + write_index, write_size);
//write_index不是静态局部变量,此处有意义?
write_index += write_size;
size -= write_size;
buf_write_size += write_size;
/* output log /
elog_port_output(log_buf, buf_write_size);
/
reset write index */
buf_write_size = 0;
} else {
memcpy(log_buf + buf_write_size, log + write_index, size);
buf_write_size += size;
break;
}
}
}`

修改成以下代码后测试正常:
`void elog_buf_output(const char *log, size_t size)
{
//未使能缓冲输出时直接输出
if (!is_enabled) {
elog_port_output(log, size);
return;
}
//缓冲区空间不足时先输出
if (buf_write_size + size > ELOG_BUF_OUTPUT_BUF_SIZE) {
elog_port_output(log_buf, buf_write_size);
buf_write_size = 0;
}
//日志拷贝至缓冲区
memcpy(log_buf + buf_write_size, log, size);
buf_write_size += size;

}`

@armink
Copy link
Owner

armink commented Mar 30, 2019

buf 缓冲模式,基本没有被应用,有问题欢迎提交 pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants