@@ -29,6 +29,9 @@ struct ResourceManager {
29
29
30
30
static void processHandler (const DataTransferStatusChange& handler, int64_t consumedBytes, int64_t totalBytes,
31
31
int64_t rwOnceBytes, DataTransferType type, void * userData) {
32
+ if (!handler){
33
+ return ;
34
+ }
32
35
DataTransferStatus dataTransferStatus{consumedBytes, totalBytes, rwOnceBytes, type, userData};
33
36
auto data = std::make_shared<DataTransferStatus>(dataTransferStatus);
34
37
handler (data);
@@ -38,9 +41,12 @@ static size_t sendBody(char* ptr, size_t size, size_t nmemb, void* data) {
38
41
auto * resourceMan = static_cast <ResourceManager*>(data);
39
42
40
43
if (resourceMan == nullptr || resourceMan->httpReq == nullptr ) {
41
- resourceMan->dataTransferType = 4 ;
42
- processHandler (resourceMan->progress , resourceMan->send , resourceMan->total , 0 , resourceMan->dataTransferType ,
43
- resourceMan->userData );
44
+ if (resourceMan != nullptr ) {
45
+ resourceMan->dataTransferType = 4 ;
46
+ processHandler (resourceMan->progress , resourceMan->send , resourceMan->total , 0 , resourceMan->dataTransferType ,
47
+ resourceMan->userData );
48
+ }
49
+
44
50
return 0 ;
45
51
}
46
52
std::shared_ptr<std::iostream>& content = resourceMan->httpReq ->Body ();
@@ -95,6 +101,8 @@ static size_t recvBody(char* ptr, size_t size, size_t nmemb, void* userdata) {
95
101
auto * resourceMan = static_cast <ResourceManager*>(userdata);
96
102
const size_t wanted = size * nmemb;
97
103
104
+ auto logger = LogUtils::GetLogger ();
105
+
98
106
// 第一次回调
99
107
if (resourceMan->progress && resourceMan->dataTransferType == 1 ) {
100
108
if (resourceMan->total == -1 ) {
@@ -117,9 +125,12 @@ static size_t recvBody(char* ptr, size_t size, size_t nmemb, void* userdata) {
117
125
}
118
126
119
127
if (resourceMan == nullptr || resourceMan->httpResp == nullptr || wanted == 0 ) {
120
- resourceMan->dataTransferType = 4 ;
121
- processHandler (resourceMan->progress , resourceMan->send , resourceMan->total , 0 , resourceMan->dataTransferType ,
122
- resourceMan->userData );
128
+ if (resourceMan != nullptr ) {
129
+ resourceMan->dataTransferType = 4 ;
130
+ processHandler (resourceMan->progress , resourceMan->send , resourceMan->total , 0 , resourceMan->dataTransferType ,
131
+ resourceMan->userData );
132
+ }
133
+
123
134
return -1 ;
124
135
}
125
136
// 第一次receive response body , 初始化state->resposne->body
@@ -136,6 +147,9 @@ static size_t recvBody(char* ptr, size_t size, size_t nmemb, void* userdata) {
136
147
}
137
148
std::shared_ptr<std::iostream>& content = resourceMan->httpResp ->Body ();
138
149
if (content == nullptr || content->fail ()) {
150
+ if (logger != nullptr ) {
151
+ logger->error (" recvBody content init err" );
152
+ }
139
153
resourceMan->dataTransferType = 4 ;
140
154
processHandler (resourceMan->progress , resourceMan->send , resourceMan->total , 0 , resourceMan->dataTransferType ,
141
155
resourceMan->userData );
@@ -147,6 +161,9 @@ static size_t recvBody(char* ptr, size_t size, size_t nmemb, void* userdata) {
147
161
// }
148
162
149
163
if (content->bad ()) {
164
+ if (logger != nullptr ) {
165
+ logger->error (" recvBody content write err, please check disk space, file permission, network, etc." );
166
+ }
150
167
resourceMan->dataTransferType = 4 ;
151
168
processHandler (resourceMan->progress , resourceMan->send , resourceMan->total , 0 , resourceMan->dataTransferType ,
152
169
resourceMan->userData );
0 commit comments