Optimize QUIC write
This commit is contained in:
parent
c591ab5e6f
commit
a93eb8b8f5
|
@ -214,8 +214,7 @@ void readcb(struct ev_loop *loop, ev_io *w, int revents) {
|
||||||
delete client;
|
delete client;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
writecb(loop, &client->wev, revents);
|
client->signal_write();
|
||||||
// client->disconnect() and client->fail() may be called
|
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
|
@ -601,35 +601,40 @@ int Client::read_quic() {
|
||||||
sockaddr_union su;
|
sockaddr_union su;
|
||||||
socklen_t addrlen = sizeof(su);
|
socklen_t addrlen = sizeof(su);
|
||||||
int rv;
|
int rv;
|
||||||
|
size_t pktcnt = 0;
|
||||||
|
|
||||||
auto nread =
|
for (;;) {
|
||||||
recvfrom(fd, buf.data(), buf.size(), MSG_DONTWAIT, &su.sa, &addrlen);
|
auto nread =
|
||||||
if (nread == -1) {
|
recvfrom(fd, buf.data(), buf.size(), MSG_DONTWAIT, &su.sa, &addrlen);
|
||||||
return 0;
|
if (nread == -1) {
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
assert(quic.conn);
|
assert(quic.conn);
|
||||||
|
|
||||||
auto path = ngtcp2_path{
|
auto path = ngtcp2_path{
|
||||||
{local_addr.len, reinterpret_cast<uint8_t *>(&local_addr.su.sa)},
|
{local_addr.len, reinterpret_cast<uint8_t *>(&local_addr.su.sa)},
|
||||||
{addrlen, reinterpret_cast<uint8_t *>(&su.sa)},
|
{addrlen, reinterpret_cast<uint8_t *>(&su.sa)},
|
||||||
};
|
};
|
||||||
|
|
||||||
rv = ngtcp2_conn_read_pkt(quic.conn, &path, buf.data(), nread,
|
rv = ngtcp2_conn_read_pkt(quic.conn, &path, buf.data(), nread,
|
||||||
timestamp(worker->loop));
|
timestamp(worker->loop));
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
std::cerr << "ngtcp2_conn_read_pkt: " << ngtcp2_strerror(rv) << std::endl;
|
std::cerr << "ngtcp2_conn_read_pkt: " << ngtcp2_strerror(rv) << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worker->current_phase == Phase::MAIN_DURATION) {
|
if (pktcnt == 10) {
|
||||||
worker->stats.bytes_total += nread;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Client::write_quic() {
|
int Client::write_quic() {
|
||||||
|
ev_io_stop(worker->loop, &wev);
|
||||||
|
|
||||||
if (quic.close_requested) {
|
if (quic.close_requested) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue