From 562d66799c183ce0ad6f9f242b700c13b6de1b5f Mon Sep 17 00:00:00 2001 From: zhaohe Date: Fri, 5 Jan 2024 22:41:35 +0800 Subject: [PATCH] update --- xs_udp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xs_udp.c b/xs_udp.c index 651efcd..aad5c60 100644 --- a/xs_udp.c +++ b/xs_udp.c @@ -49,11 +49,12 @@ bool xs_udp_init(udp_t *udp_handler, const char *name, uint16_t port, udp_on_pac ZLOGE(TAG, "create socket fail"); return false; } - // 设置超时 - struct timeval tv = {0, 1000}; - SOCKET_DO(lwip_setsockopt(udp_handler->sock_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv))); + // 绑定 SOCKET_DO(bind(udp_handler->sock_fd, (struct sockaddr *)&udp_handler->server, sizeof(udp_handler->server))); + // 设置超时 + struct timeval tv = {1, 0}; + SOCKET_DO(lwip_setsockopt(udp_handler->sock_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv))); if (on_packet) { // 创建接收线程 @@ -88,7 +89,7 @@ bool xs_udp_broadcast_init(udp_broadcast_handler_t *udp_handler, uint16_t localp return false; } // 设置超时 - struct timeval tv = {0, 1000}; + struct timeval tv = {1, 0}; SOCKET_DO(lwip_setsockopt(udp_handler->sock_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv))); // 绑定 SOCKET_DO(bind(udp_handler->sock_fd, (struct sockaddr *)&udp_handler->server, sizeof(udp_handler->server)));