@cryptotaxi247 / netdata-1 / commits / df71e1abd

cleanup in web_client

Costa Tsaousis (ktsaou) committed May 8, 2015 at 21:38 UTC df71e1abdc55a94e1d514d9f6c5c494ff963afa3
1 file changed +25 -31
src/web_client.c
+25 -31
@@ -1150,7 +1150,7 @@ long web_client_receive(struct web_client *w)
1150 // in this case, the error should be generated when the file has been sent to the client.
1151
1152 if(w->mode == WEB_CLIENT_MODE_FILECOPY) {
1153 - // we are copying data fron ifd to ofd
1153 + // we are copying data from ifd to ofd
1154 // let it finish copying...
1155 w->wait_receive = 0;
1156 debug(D_WEB_CLIENT, "%llu: Disabling input.", w->id);
@@ -1219,62 +1219,56 @@ void *web_client_main(void *ptr)
1219 }
1220 else if(!retval) {
1221 // timeout
1222 - web_client_reset(w);
1223 - w->obsolete = 1;
1224 - return NULL;
1222 + debug(D_WEB_CLIENT_ACCESS, "%llu: LISTENER: timeout.", w->id);
1223 + break;
1224 }
1225
1226 if(FD_ISSET(w->ifd, &efds)) {
1227 debug(D_WEB_CLIENT_ACCESS, "%llu: Received error on input socket (%s).", w->id, strerror(errno));
1229 - web_client_reset(w);
1230 - w->obsolete = 1;
1231 - return NULL;
1228 + break;
1229 }
1230
1231 if(FD_ISSET(w->ofd, &efds)) {
1232 debug(D_WEB_CLIENT_ACCESS, "%llu: Received error on output socket (%s).", w->id, strerror(errno));
1236 - web_client_reset(w);
1237 - w->obsolete = 1;
1238 - return NULL;
1233 + break;
1234 }
1235
1236 if(w->wait_send && FD_ISSET(w->ofd, &ofds)) {
1237 long bytes;
1238 if((bytes = web_client_send(w)) < 0) {
1244 - debug(D_WEB_CLIENT, "%llu: Closing client (input: %s).", w->id, strerror(errno));
1245 - web_client_reset(w);
1246 - w->obsolete = 1;
1239 + debug(D_WEB_CLIENT, "%llu: Cannot send data to client. Closing client (ouput: %s).", w->id, strerror(errno));
1240 errno = 0;
1248 - return NULL;
1249 - }
1250 - else {
1251 - global_statistics_lock();
1252 - global_statistics.bytes_sent += bytes;
1253 - global_statistics_unlock();
1241 + break;
1242 }
1243 +
1244 + global_statistics_lock();
1245 + global_statistics.bytes_sent += bytes;
1246 + global_statistics_unlock();
1247 }
1248
1249 if(w->wait_receive && FD_ISSET(w->ifd, &ifds)) {
1250 long bytes;
1251 if((bytes = web_client_receive(w)) < 0) {
1260 - debug(D_WEB_CLIENT, "%llu: Closing client (output: %s).", w->id, strerror(errno));
1261 - web_client_reset(w);
1262 - w->obsolete = 1;
1252 + debug(D_WEB_CLIENT, "%llu: Cannot receive data from client. Closing client (input: %s).", w->id, strerror(errno));
1253 errno = 0;
1264 - return NULL;
1265 - }
1266 - else {
1267 - if(w->mode != WEB_CLIENT_MODE_FILECOPY) {
1268 - global_statistics_lock();
1269 - global_statistics.bytes_received += bytes;
1270 - global_statistics_unlock();
1271 - }
1254 + break;
1255 }
1256
1274 - if(w->mode == WEB_CLIENT_MODE_NORMAL) web_client_process(w);
1257 + global_statistics_lock();
1258 + global_statistics.bytes_received += bytes;
1259 + global_statistics_unlock();
1260 +
1261 + if(w->mode == WEB_CLIENT_MODE_NORMAL) {
1262 + debug(D_WEB_CLIENT, "%llu: Attempting to process received data.", w->id);
1263 + web_client_process(w);
1264 + }
1265 }
1266 }
1267 +
1268 debug(D_WEB_CLIENT, "%llu: done...", w->id);
1269
1270 + web_client_reset(w);
1271 + w->obsolete = 1;
1272 +
1273 return NULL;
1274 }