From 0f6d4ca629e92a3c8dc8228d4b5308187188d116 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 23 Apr 2019 12:25:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96http=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpClient.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index 3181efe6..eda7ffc3 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -185,8 +185,13 @@ int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) { //但是由于我们没必要等content接收完毕才回调onRecvContent(因为这样浪费内存并且要多次拷贝数据) //所以返回-1代表我们接下来分段接收content _recvedBodySize = 0; - //根据_totalBodySize设置接收缓存大小 - _sock->setReadBuffer(std::make_shared(MIN(_totalBodySize + 1,256 * 1024))); + if(_totalBodySize > 0){ + //根据_totalBodySize设置接收缓存大小 + _sock->setReadBuffer(std::make_shared(MIN(_totalBodySize + 1,256 * 1024))); + }else{ + _sock->setReadBuffer(std::make_shared(256 * 1024)); + } + return -1; }