tcp/quic lab and switch lab added
This commit is contained in:
@@ -103,7 +103,7 @@ int main(int argc, char *argv[]) {
|
||||
client->sock = sock;
|
||||
client->peer_addr = peer_addr;
|
||||
client->peer_addr_len = peer_addr_len;
|
||||
|
||||
|
||||
uint8_t server_scid[QUICHE_MAX_CONN_ID_LEN];
|
||||
int rng = open("/dev/urandom", O_RDONLY);
|
||||
if (rng >= 0) {
|
||||
@@ -117,7 +117,7 @@ int main(int argc, char *argv[]) {
|
||||
printf("New performance connection accepted.\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (client != NULL) {
|
||||
quiche_conn_recv(client->conn, buf, read_len, &(quiche_recv_info){
|
||||
.to = (struct sockaddr *)&sa,
|
||||
@@ -131,7 +131,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (client != NULL) {
|
||||
quiche_conn *conn = client->conn;
|
||||
|
||||
|
||||
if (quiche_conn_is_closed(conn)) {
|
||||
printf("Connection closed.\n");
|
||||
quiche_conn_free(conn);
|
||||
@@ -148,7 +148,7 @@ int main(int argc, char *argv[]) {
|
||||
clock_gettime(CLOCK_MONOTONIC, &client->start_time);
|
||||
client->timer_started = 1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t recv_buf[65535];
|
||||
bool fin = false;
|
||||
uint64_t err_code = 0;
|
||||
@@ -162,7 +162,7 @@ int main(int argc, char *argv[]) {
|
||||
double time_taken = (end.tv_sec - client->start_time.tv_sec) + (end.tv_nsec - client->start_time.tv_nsec) / 1e9;
|
||||
double mb = client->total_bytes / (1024.0 * 1024.0);
|
||||
double throughput = mb / time_taken;
|
||||
|
||||
|
||||
if (!done_printing) {
|
||||
printf("Received %.2f MB in %.2f seconds.\n", mb, time_taken);
|
||||
printf("Throughput: %.2f MB/s\n", throughput);
|
||||
@@ -172,18 +172,24 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
quiche_stream_iter_free(readable);
|
||||
}
|
||||
|
||||
|
||||
bool has_outgoing = false;
|
||||
while (1) {
|
||||
quiche_send_info send_info;
|
||||
ssize_t written = quiche_conn_send(conn, out, sizeof(out), &send_info);
|
||||
if (written == QUICHE_ERR_DONE) break;
|
||||
if (written < 0) break;
|
||||
sendto(sock, out, written, 0, (struct sockaddr *)&send_info.to, send_info.to_len);
|
||||
has_outgoing = true;
|
||||
}
|
||||
|
||||
|
||||
quiche_conn_on_timeout(conn);
|
||||
|
||||
// 使用更短的轮询间隔以提高响应速度
|
||||
if (!has_outgoing) {
|
||||
usleep(100); // 100微秒轮询
|
||||
}
|
||||
}
|
||||
usleep(100);
|
||||
}
|
||||
|
||||
quiche_config_free(config);
|
||||
|
||||
Reference in New Issue
Block a user