Skip to content

Commit

Permalink
[~] fix CR LF check for hq
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanmei-Liu committed Nov 4, 2023
1 parent a730ce7 commit 3dafe99
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions demo/xqc_hq_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ xqc_hq_request_send_rsp(xqc_hq_request_t *hqr, const uint8_t *res_buf, size_t re


ssize_t
xqc_hq_parse_req(xqc_hq_request_t *hqr, char *res, size_t sz)
xqc_hq_parse_req(xqc_hq_request_t *hqr, char *res, size_t sz, uint8_t *fin)
{
char method[16] = {0};
int ret = sscanf(hqr->req_recv_buf, "%s %s", method, res);
Expand All @@ -244,6 +244,15 @@ xqc_hq_parse_req(xqc_hq_request_t *hqr, char *res, size_t sz)
return -XQC_EPROTO;
}

if (ret + 2 <= hqr->recv_buf_len
&& (*(hqr->req_recv_buf + ret) == '\r')
&& (*(hqr->req_recv_buf + ret + 1) == '\n'))
{
/* check CR LF for hq request line */
*fin = 1;
PRINT_LOG("|hq recv CR LF|%zd|", read);
}

return strlen(res);
}

Expand Down Expand Up @@ -291,25 +300,16 @@ xqc_hq_request_recv_req(xqc_hq_request_t *hqr, char *res_buf, size_t buf_sz, uin
}

uint8_t req_fin = 0;
read = xqc_hq_parse_req(hqr, hqr->resource_buf, XQC_HQ_REQUEST_RESOURCE_MAX_LEN);
read = xqc_hq_parse_req(hqr, hqr->resource_buf, XQC_HQ_REQUEST_RESOURCE_MAX_LEN, &req_fin);
if (read <= 0) {
if (!hqr->fin) {
return -XQC_EAGAIN;
/* return until all request bytes are received in the current request */
return XQC_OK;
} else {
return -XQC_EPROTO;
}
}

if (read > 0
&& read + 2 <= hqr->recv_buf_len
&& (*(hqr->req_recv_buf + read) == '\r')
&& (*(hqr->req_recv_buf + read + 1) == '\n'))
{
/* check CR LF for hq request line */
req_fin = 1;
PRINT_LOG("|hq recv CR LF|%zd|", read);
}

/* return until all request bytes are received in the current request */
if (!hqr->fin && !req_fin) {
return XQC_OK;
Expand Down

0 comments on commit 3dafe99

Please sign in to comment.