Optimize QUIC write

This commit is contained in:
Tatsuhiro Tsujikawa 2019-11-20 23:40:51 +09:00
parent 1d05c6c3c5
commit aa7c580bb1
2 changed files with 24 additions and 20 deletions

View File

@ -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

View File

@ -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;
} }