fix for lost bytes on filecopy #40
Costa Tsaousis (ktsaou) committed
Dec 30, 2015 at 06:01 UTC
f605cd4d3f13c784566f6c2e5ce813cecd62655a
1 file changed
+12
-6
src/web_client.c
+12
-6
@@ -1435,7 +1435,7 @@ long web_client_send_deflate(struct web_client *w)
1435
// when using compression,
1436
// w->response.sent is the amount of bytes passed through compression
1437
1438
- debug(D_DEFLATE, "%llu: TEST w->response.data->len = %d, w->response.sent = %d, w->response.zhave = %d, w->response.zsent = %d, w->response.zstream.avail_in = %d, w->response.zstream.avail_out = %d, w->response.zstream.total_in = %d, w->response.zstream.total_out = %d.", w->id, w->response.data->len, w->response.sent, w->response.zhave, w->response.zsent, w->response.zstream.avail_in, w->response.zstream.avail_out, w->response.zstream.total_in, w->response.zstream.total_out);
1438
+ debug(D_DEFLATE, "%llu: web_client_send_deflate(): w->response.data->len = %d, w->response.sent = %d, w->response.zhave = %d, w->response.zsent = %d, w->response.zstream.avail_in = %d, w->response.zstream.avail_out = %d, w->response.zstream.total_in = %d, w->response.zstream.total_out = %d.", w->id, w->response.data->len, w->response.sent, w->response.zhave, w->response.zsent, w->response.zstream.avail_in, w->response.zstream.avail_out, w->response.zstream.total_in, w->response.zstream.total_out);
1439
1440
if(w->response.data->len - w->response.sent == 0 && w->response.zstream.avail_in == 0 && w->response.zhave == w->response.zsent && w->response.zstream.avail_out != 0) {
1441
// there is nothing to send
@@ -1475,12 +1475,16 @@ long web_client_send_deflate(struct web_client *w)
1475
// close the previous open chunk
1476
if(w->response.sent != 0) t += web_client_send_chunk_close(w);
1477
1478
- debug(D_DEFLATE, "%llu: Compressing %d bytes starting from %d.", w->id, (w->response.data->len - w->response.sent), w->response.sent);
1478
+ debug(D_DEFLATE, "%llu: Compressing %d new bytes starting from %d (and %d left behind).", w->id, (w->response.data->len - w->response.sent), w->response.sent, w->response.zstream.avail_in);
1479
1480
// give the compressor all the data not passed through the compressor yet
1481
if(w->response.data->len > w->response.sent) {
1482
- w->response.zstream.next_in = (Bytef *)&w->response.data->buffer[w->response.sent];
1483
- w->response.zstream.avail_in = (uInt) (w->response.data->len - w->response.sent);
1482
+#ifdef NETDATA_INTERNAL_CHECKS
1483
+ if(w->response.sent - w->response.zstream.avail_in < 0)
1484
+ error("internal error: avail_in is corrupted.");
1485
+#endif
1486
+ w->response.zstream.next_in = (Bytef *)&w->response.data->buffer[w->response.sent - w->response.zstream.avail_in];
1487
+ w->response.zstream.avail_in += (uInt) (w->response.data->len - w->response.sent);
1488
}
1489
1490
// reset the compressor output buffer
@@ -1490,9 +1494,9 @@ long web_client_send_deflate(struct web_client *w)
1494
// ask for FINISH if we have all the input
1495
int flush = Z_SYNC_FLUSH;
1496
if(w->mode == WEB_CLIENT_MODE_NORMAL
1493
- || (w->mode == WEB_CLIENT_MODE_FILECOPY && w->response.data->len == w->response.rlen)) {
1497
+ || (w->mode == WEB_CLIENT_MODE_FILECOPY && !w->wait_receive && w->response.data->len == w->response.rlen)) {
1498
flush = Z_FINISH;
1495
- debug(D_DEFLATE, "%llu: Requesting Z_FINISH.", w->id);
1499
+ debug(D_DEFLATE, "%llu: Requesting Z_FINISH, if possible.", w->id);
1500
}
1501
else {
1502
debug(D_DEFLATE, "%llu: Requesting Z_SYNC_FLUSH.", w->id);
@@ -1516,6 +1520,8 @@ long web_client_send_deflate(struct web_client *w)
1520
// open a new chunk
1521
t += web_client_send_chunk_header(w, w->response.zhave);
1522
}
1523
+
1524
+ debug(D_WEB_CLIENT, "%llu: Sending %d bytes of data (+%d of chunk header).", w->id, w->response.zhave - w->response.zsent, t);
1525
1526
len = send(w->ofd, &w->response.zbuffer[w->response.zsent], (size_t) (w->response.zhave - w->response.zsent), MSG_DONTWAIT);
1527
if(len > 0) {