From c680a1d75af2e9b104ea92669872d74e9e8127b6 Mon Sep 17 00:00:00 2001 From: yangchen Date: Thu, 10 Oct 2024 12:32:41 +0800 Subject: [PATCH] set send timeout to 10s set send timeout to 10s,avoid getting stuck in the send() function for a long time when there is no space in send buffer --- lldp/l2_packet_linux.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lldp/l2_packet_linux.c b/lldp/l2_packet_linux.c index be9b8af..4ce5e76 100644 --- a/lldp/l2_packet_linux.c +++ b/lldp/l2_packet_linux.c @@ -220,6 +220,12 @@ struct l2_packet_data * l2_packet_init( ifname, MAC2STR(l2->curr_mac_addr), MAC2STR(l2->perm_mac_addr), MAC2STR(l2->san_mac_addr)); + struct timeval timeout; + timeout.tv_sec = 10; + timeout.tv_usec = 0; + socklen_t len = sizeof(timeout); + setsockopt(l2->fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, len); + struct packet_mreq mr; memset(&mr, 0, sizeof(mr)); mr.mr_ifindex = l2->ifindex; -- 2.33.0