Permalink
Browse files

Fixed bug in chunked transfers to the printer

Chunked HTTP transfers allow streaming and therefore they are used to
send larger amounts of data (Usually print jobs) to the printer. There
was a bug that made an HTTP message being considered completed when
the buffer space was full, ignoring the fact that packages can be
larger and that therefore the space gets expanded if necessary. This
made print jobs (except tiny ones, probably the ones smaller than the
initial buffer size of 4kB) hanging but instructions and queries
(which are transfered in content-length mode) working normally.
  • Loading branch information...
1 parent e298768 commit 3facde24a3b74168047dcd564bf609fd9911edcb @tillkamppeter committed Jul 15, 2015
Showing with 4 additions and 7 deletions.
  1. +4 −7 src/http.c
View
@@ -64,11 +64,8 @@ static void packet_check_completion(struct http_packet_t *pkt)
if (pkt->expected_size && pkt->filled_size >= pkt->expected_size)
pkt->is_completed = 1;
- // Pkt at capacity
- if (pkt->filled_size == pkt->buffer_capacity) {
- pkt->is_completed = 1;
- msg->is_completed = 1;
- } else if (pkt->filled_size > pkt->buffer_capacity) {
+ // Pkt over capacity
+ if (pkt->filled_size > pkt->buffer_capacity) {
// Santiy check
ERR_AND_EXIT("Overflowed packet buffer");
}
@@ -501,8 +498,6 @@ size_t packet_pending_bytes(struct http_packet_t *pkt)
ERR_AND_EXIT("Expected cannot be larger than filled");
size_t pending = expected - pkt->filled_size;
-
- packet_check_completion(pkt);
// Expand buffer as needed
while (pending + pkt->filled_size > pkt->buffer_capacity) {
@@ -517,6 +512,8 @@ size_t packet_pending_bytes(struct http_packet_t *pkt)
}
}
+ packet_check_completion(pkt);
+
return pending;
}

0 comments on commit 3facde2

Please sign in to comment.