Don't read greedily
@@ -2724,7 +2724,6 @@ int Server::on_read(Endpoint &ep) {
int rv;
ngtcp2_pkt_hd hd;
- while (true) {
addrlen = sizeof(su);
auto nread =
recvfrom(ep.fd, buf.data(), buf.size(), MSG_DONTWAIT, &su.sa, &addrlen);
@@ -2750,19 +2749,18 @@ int Server::on_read(Endpoint &ep) {
}
if (nread == 0) {
- continue;
+ return 0;
}
if (buf[0] & 0x80) {
rv = ngtcp2_pkt_decode_hd_long(&hd, buf.data(), nread);
} else {
// TODO For Short packet, we just need DCID.
- rv =
- ngtcp2_pkt_decode_hd_short(&hd, buf.data(), nread, NGTCP2_SV_SCIDLEN);
+ rv = ngtcp2_pkt_decode_hd_short(&hd, buf.data(), nread, NGTCP2_SV_SCIDLEN);
}
if (rv < 0) {
- std::cerr << "Could not decode QUIC packet header: "
- << ngtcp2_strerror(rv) << std::endl;
+ std::cerr << "Could not decode QUIC packet header: " << ngtcp2_strerror(rv)
+ << std::endl;
return 0;
}
@@ -2873,7 +2871,6 @@ int Server::on_read(Endpoint &ep) {
default:
remove(h);
}
- }
return 0;
}
