Skip to content

Commit 256a197

Browse files
authored
[~] fix: demo_client is unable to process empty FIN for h3 streams (#484)
1 parent 994040a commit 256a197

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

demo/demo_client.c

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,39 +1231,43 @@ xqc_demo_cli_h3_request_read_notify(xqc_h3_request_t *h3_request, xqc_request_no
12311231
}
12321232

12331233
/* continue to recv body */
1234-
if (!(flag & XQC_REQ_NOTIFY_READ_BODY)) {
1235-
return 0;
1236-
}
1234+
if (flag & XQC_REQ_NOTIFY_READ_BODY) {
12371235

1238-
char buff[4096] = {0};
1239-
size_t buff_size = 4096;
1236+
char buff[4096] = {0};
1237+
size_t buff_size = 4096;
12401238

1241-
ssize_t read = 0;
1242-
ssize_t read_sum = 0;
1243-
do {
1244-
read = xqc_h3_request_recv_body(h3_request, buff, buff_size, &fin);
1245-
if (read == -XQC_EAGAIN) {
1246-
break;
1239+
ssize_t read = 0;
1240+
ssize_t read_sum = 0;
1241+
do {
1242+
read = xqc_h3_request_recv_body(h3_request, buff, buff_size, &fin);
1243+
if (read == -XQC_EAGAIN) {
1244+
break;
12471245

1248-
} else if (read < 0) {
1249-
printf("xqc_h3_request_recv_body error %zd\n", read);
1250-
return 0;
1251-
}
1246+
} else if (read < 0) {
1247+
printf("xqc_h3_request_recv_body error %zd\n", read);
1248+
return 0;
1249+
}
12521250

1253-
if (user_stream->recv_body_fp) {
1254-
if (fwrite(buff, 1, read, user_stream->recv_body_fp) != read) {
1255-
printf("fwrite error\n");
1256-
return -1;
1251+
if (user_stream->recv_body_fp) {
1252+
if (fwrite(buff, 1, read, user_stream->recv_body_fp) != read) {
1253+
printf("fwrite error\n");
1254+
return -1;
1255+
}
1256+
fflush(user_stream->recv_body_fp);
12571257
}
1258-
fflush(user_stream->recv_body_fp);
1259-
}
12601258

1261-
read_sum += read;
1262-
user_stream->recv_body_len += read;
1263-
} while (read > 0 && !fin);
1259+
read_sum += read;
1260+
user_stream->recv_body_len += read;
1261+
} while (read > 0 && !fin);
1262+
1263+
if (read > 0) {
1264+
printf("xqc_h3_request_recv_body size %zd, fin:%d\n", read, fin);
1265+
}
1266+
}
12641267

1265-
if (read > 0) {
1266-
printf("xqc_h3_request_recv_body size %zd, fin:%d\n", read, fin);
1268+
if (flag & XQC_REQ_NOTIFY_READ_EMPTY_FIN) {
1269+
printf("empty fin received!\n");
1270+
fin = 1;
12671271
}
12681272

12691273
if (fin) {

0 commit comments

Comments
 (0)