Simplify write_quic
This commit is contained in:
parent
1aae450303
commit
53a860a5bf
|
@ -1362,6 +1362,9 @@ int Client::write_udp(const sockaddr *addr, socklen_t addrlen,
|
||||||
if (nwrite < 0) {
|
if (nwrite < 0) {
|
||||||
std::cerr << "sendto: errno=" << errno << std::endl;
|
std::cerr << "sendto: errno=" << errno << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ev_io_stop(worker->loop, &wev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -602,32 +602,6 @@ int Client::write_quic() {
|
||||||
|
|
||||||
ngtcp2_path_storage_zero(&ps);
|
ngtcp2_path_storage_zero(&ps);
|
||||||
|
|
||||||
if (!session) {
|
|
||||||
auto nwrite =
|
|
||||||
ngtcp2_conn_write_pkt(quic.conn, &ps.path, buf.data(), quic.max_pktlen,
|
|
||||||
timestamp(worker->loop));
|
|
||||||
if (nwrite < 0) {
|
|
||||||
quic.last_error = quic::err_transport(nwrite);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
quic_restart_pkt_timer();
|
|
||||||
|
|
||||||
if (nwrite) {
|
|
||||||
write_udp(reinterpret_cast<sockaddr *>(ps.path.remote.addr),
|
|
||||||
ps.path.remote.addrlen, buf.data(), nwrite);
|
|
||||||
|
|
||||||
ev_io_start(worker->loop, &wev);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// session might be initialized during ngtcp2_conn_write_pkt.
|
|
||||||
if (!session) {
|
|
||||||
ev_io_stop(worker->loop, &wev);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto s = static_cast<Http3Session *>(session.get());
|
auto s = static_cast<Http3Session *>(session.get());
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -635,7 +609,7 @@ int Client::write_quic() {
|
||||||
int fin = 0;
|
int fin = 0;
|
||||||
ssize_t sveccnt = 0;
|
ssize_t sveccnt = 0;
|
||||||
|
|
||||||
if (ngtcp2_conn_get_max_data_left(quic.conn)) {
|
if (session && ngtcp2_conn_get_max_data_left(quic.conn)) {
|
||||||
sveccnt = s->write_stream(stream_id, fin, vec.data(), vec.size());
|
sveccnt = s->write_stream(stream_id, fin, vec.data(), vec.size());
|
||||||
if (sveccnt == -1) {
|
if (sveccnt == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -643,40 +617,14 @@ int Client::write_quic() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ndatalen;
|
ssize_t ndatalen;
|
||||||
if (sveccnt == 0 && stream_id == -1) {
|
|
||||||
auto nwrite =
|
|
||||||
ngtcp2_conn_write_pkt(quic.conn, &ps.path, buf.data(),
|
|
||||||
quic.max_pktlen, timestamp(worker->loop));
|
|
||||||
if (nwrite < 0) {
|
|
||||||
quic.last_error = quic::err_transport(nwrite);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
quic_restart_pkt_timer();
|
|
||||||
|
|
||||||
if (nwrite == 0) {
|
|
||||||
ev_io_stop(worker->loop, &wev);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
write_udp(reinterpret_cast<sockaddr *>(ps.path.remote.addr),
|
|
||||||
ps.path.remote.addrlen, buf.data(), nwrite);
|
|
||||||
|
|
||||||
ev_io_start(worker->loop, &wev);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto v = vec.data();
|
auto v = vec.data();
|
||||||
auto vcnt = static_cast<size_t>(sveccnt);
|
auto vcnt = static_cast<size_t>(sveccnt);
|
||||||
for (;;) {
|
|
||||||
auto nwrite = ngtcp2_conn_writev_stream(
|
auto nwrite = ngtcp2_conn_writev_stream(
|
||||||
quic.conn, &ps.path, buf.data(), quic.max_pktlen, &ndatalen,
|
quic.conn, &ps.path, buf.data(), quic.max_pktlen, &ndatalen,
|
||||||
NGTCP2_WRITE_STREAM_FLAG_MORE, stream_id, fin,
|
NGTCP2_WRITE_STREAM_FLAG_MORE, stream_id, fin,
|
||||||
reinterpret_cast<const ngtcp2_vec *>(v), vcnt,
|
reinterpret_cast<const ngtcp2_vec *>(v), vcnt, timestamp(worker->loop));
|
||||||
timestamp(worker->loop));
|
|
||||||
if (nwrite < 0) {
|
if (nwrite < 0) {
|
||||||
auto should_break = false;
|
|
||||||
switch (nwrite) {
|
switch (nwrite) {
|
||||||
case NGTCP2_ERR_STREAM_DATA_BLOCKED:
|
case NGTCP2_ERR_STREAM_DATA_BLOCKED:
|
||||||
case NGTCP2_ERR_STREAM_SHUT_WR:
|
case NGTCP2_ERR_STREAM_SHUT_WR:
|
||||||
|
@ -688,19 +636,13 @@ int Client::write_quic() {
|
||||||
if (s->block_stream(stream_id) != 0) {
|
if (s->block_stream(stream_id) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
should_break = true;
|
continue;
|
||||||
break;
|
|
||||||
case NGTCP2_ERR_WRITE_STREAM_MORE:
|
case NGTCP2_ERR_WRITE_STREAM_MORE:
|
||||||
assert(ndatalen > 0);
|
assert(ndatalen > 0);
|
||||||
if (s->add_write_offset(stream_id, ndatalen) != 0) {
|
if (s->add_write_offset(stream_id, ndatalen) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
should_break = true;
|
continue;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (should_break) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quic.last_error = quic::err_transport(nwrite);
|
quic.last_error = quic::err_transport(nwrite);
|
||||||
|
@ -710,7 +652,6 @@ int Client::write_quic() {
|
||||||
quic_restart_pkt_timer();
|
quic_restart_pkt_timer();
|
||||||
|
|
||||||
if (nwrite == 0) {
|
if (nwrite == 0) {
|
||||||
ev_io_stop(worker->loop, &wev);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,11 +663,6 @@ int Client::write_quic() {
|
||||||
|
|
||||||
write_udp(reinterpret_cast<sockaddr *>(ps.path.remote.addr),
|
write_udp(reinterpret_cast<sockaddr *>(ps.path.remote.addr),
|
||||||
ps.path.remote.addrlen, buf.data(), nwrite);
|
ps.path.remote.addrlen, buf.data(), nwrite);
|
||||||
|
|
||||||
ev_io_start(worker->loop, &wev);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue