Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
buf.clear();
会重置缓冲区的主要索引值,不必为了每次读写都创建新的缓冲区;如果在下次写入之前不这么做,那么下次写入总是失败的。这将导致while循环总是只执行一次,每次http链接只能传输513字节长度的数据,降低效率。以下是测试数据:
未添加
buf.clear();
时:让我们看看while循环执行的情况:
显然,第二次写buf总是失败,长度为0,导致while循环只能执行1次。数据将会被分成多次http连接传递,降低传输效率。
添加
buf.clear();
时:单次可传递数据明显变多:
curl 传输速度对比: