Skip to content

Commit 654f10b

Browse files
committed
feat(http): improved chunk reading
1 parent 5f13479 commit 654f10b

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

trunk/src/protocol/srs_protocol_http_conn.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,30 +1183,31 @@ srs_error_t SrsHttpResponseReader::read_chunked(void* data, size_t nb_data, ssiz
11831183
if (nb_read) {
11841184
*nb_read = 0;
11851185
}
1186-
} else {
1187-
// for not the last chunk, there must always exists bytes.
1188-
// left bytes in chunk, read some.
1189-
srs_assert(nb_left_chunk);
1190-
1191-
size_t nb_bytes = srs_min(nb_left_chunk, nb_data);
1192-
err = read_specified(data, nb_bytes, (ssize_t*)&nb_bytes);
1193-
1194-
// the nb_bytes used for output already read size of bytes.
1195-
if (nb_read) {
1196-
*nb_read = nb_bytes;
1197-
}
1198-
nb_left_chunk -= nb_bytes;
1186+
return err;
1187+
}
11991188

1200-
if (err != srs_success) {
1201-
return srs_error_wrap(err, "read specified");
1202-
}
1189+
// for not the last chunk, there must always exists bytes.
1190+
// left bytes in chunk, read some.
1191+
srs_assert(nb_left_chunk);
12031192

1204-
// If still left bytes in chunk, ignore and read in future.
1205-
if (nb_left_chunk > 0) {
1206-
return err;
1207-
}
1193+
size_t nb_bytes = srs_min(nb_left_chunk, nb_data);
1194+
err = read_specified(data, nb_bytes, (ssize_t*)&nb_bytes);
1195+
1196+
// the nb_bytes used for output already read size of bytes.
1197+
if (nb_read) {
1198+
*nb_read = nb_bytes;
12081199
}
1209-
1200+
nb_left_chunk -= nb_bytes;
1201+
1202+
if (err != srs_success) {
1203+
return srs_error_wrap(err, "read specified");
1204+
}
1205+
1206+
// If still left bytes in chunk, ignore and read in future.
1207+
if (nb_left_chunk > 0) {
1208+
return err;
1209+
}
1210+
12101211
// for both the last or not, the CRLF of chunk payload end.
12111212
if ((err = buffer->grow(skt, 2)) != srs_success) {
12121213
return srs_error_wrap(err, "grow buffer");

0 commit comments

Comments
 (0)