acl_vstream_read_peek3 can read data to userspace buffer to decrease the data copying times.

This commit is contained in:
zhengshuxin 2019-07-09 10:25:22 +08:00
parent 8117eb885e
commit 0ffd933de4
3 changed files with 27 additions and 5 deletions

View File

@ -146,6 +146,8 @@ bool http_servlet::onUpload(request_t& req, response_t& res)
var_cfg_var_path, (unsigned) getpid(), n);
#endif
acl::meter_time(__FUNCTION__, __LINE__, "begin");
if (fp_.open_write(path)) {
// 设置原始文件存入路径
mime_->set_saved_path(path);
@ -192,6 +194,7 @@ bool http_servlet::doUpload(request_t& req, response_t& res)
// 处理完毕,需重置 HTTP 会话状态,以便于处理下一个 HTTP 请求
reset();
acl::meter_time(__FUNCTION__, __LINE__, "end");
return ret;
}
@ -213,8 +216,10 @@ bool http_servlet::upload(request_t& req, response_t& res)
break;
}
#if 0
printf(">>>size: %ld, space: %ld\r\n",
(long) buf.size(), (long) buf.capacity());
#endif
if (fp_.write(buf) == -1) {
logger_error("write error %s", acl::last_serror());
@ -254,12 +259,12 @@ bool http_servlet::upload(request_t& req, response_t& res)
// 读取 HTTP 客户端请求数据
while (content_length_ > read_length_) {
int ret = in.read_peek(buf, sizeof(buf));
printf(">>>size: %d\r\n", ret);
if (ret <= 0) {
break;
}
//printf(">>>size: %d\r\n", ret);
if (fp_.write(buf, ret) == -1) {
logger_error("write error %s", acl::last_serror());
(void) doReply(req, res, "write error");

View File

@ -1,5 +1,9 @@
修改历史列表:
657) 2019.7.9
657.1) performance: acl_vstream_read_peek3 支持根据缓冲区空间大小动态决定是否
将数据直接读到用户缓冲区中以减少数据拷贝次数
656) 2019.7.8
656.1) feature: acl_vstream.c 新增 acl_vstream_read_peek3 函数

View File

@ -1347,11 +1347,24 @@ int acl_vstream_read_peek3(ACL_VSTREAM *fp, void *buf, size_t size)
}
}
if (fp->read_ready) {
if (read_buffed(fp) <= 0) {
if (!fp->read_ready) {
return (int) (size_saved - size);
}
if (size >= (size_t) fp->read_buf_len / 4) {
size_t n = size_saved - size;
int ret = read_to_buffer(fp, ((unsigned char*) buf) + n, size);
if (ret > 0) {
return (int) (size_saved - size + ret);
}
return size_saved > size ?
(int) (size_saved - size) : ACL_VSTREAM_EOF;
}
if (read_buffed(fp) <= 0) {
return size_saved > size ?
(int) (size_saved - size) : ACL_VSTREAM_EOF;
}
if (fp->read_cnt > 0) {