|
From: | Grimes, Robert |
Subject: | [lwip-users] Problem setting receive timeouts |
Date: | Thu, 20 Dec 2012 17:01:50 +0000 |
I want to use a blocking UDP socket, and set a timeout value. If I don’t set a timeout value, then calls to lwip_recv() will (properly) block until a packet is available – great! But if I set the timeout, lwip_recv() always returns immediately,
usually with -1 – timeout. Any ideas what is wrong with my code (see below)? (Error checking omitted for clarity) mySock = lwip_socket(AF_INET, SOCK_DGRAM, 0);
// Set timeout on socket if (useTimeout) { struct timeval to; // Set for 3.01 second timeout to.tv_sec = 3; to.tv_usec = 10000; lwip_setsockopt(mySock, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof(to)); } memset(&myAddr, 0, sizeof(myAddr)); myAddr.sin_family = AF_INET; myAddr.sin_len = sizeof(myAddr); myAddr.sin_addr.s_addr = htonl(INADDR_ANY); myAddr.sin_port = htons(MY_PORT); // Set up our socket for received audio playback data lwip_bind(mySock, (struct sockaddr*)&myAddr, sizeof(myAddr)); while (1) { int numRcv = lwip_recv(mySock, &playPacket, sizeof(playPacket), 0); printf("numRcv = %d\n", numRcv); // Display received size for demonstration if (numRcv > 0) { // Process packet here } } In the above example, if useTimeout is zero, the timeout won’t be set, and the printf near the end will always print the size of the received packet, as expected. However, if useTimeout is non-zero, it will printf -1 immediately! FWIW - LWIP_SO_RCVTIMEO is set to 1 in lwipopts.h; the following are all the options in that file: #define LWIP_COMPAT_MUTEX 1 // ---------- Platform specific locking ---------- #define SYS_LIGHTWEIGHT_PROT 1 #define NO_SYS 0 // ---------- Memory options ---------- #define MEM_ALIGNMENT 4 #define MEM_SIZE 8 * 1048576 #define MEMP_OVERFLOW_CHECK 0 #define MEMP_SANITY_CHECK 0 #define MEM_USE_POOLS 0 #define MEMP_USE_CUSTOM_POOLS 0 // ---------- Internal Memory Pool Sizes ---------- #define MEMP_NUM_PBUF 128 #define MEMP_NUM_UDP_PCB 16 #define MEMP_NUM_TCP_PCB 8 #define MEMP_NUM_TCP_PCB_LISTEN 8 #define MEMP_NUM_TCP_SEG 64 #define MEMP_NUM_SYS_TIMEOUT 5 #define MEMP_NUM_NETBUF 16 #define MEMP_NUM_NETCONN 16 #define PBUF_POOL_SIZE 512 // ---------- ARP options ---------- #define ARP_TABLE_SIZE 10 #define ARP_QUEUEING 1 // ---------- IP options ---------- #define IP_FORWARD 0 #define IP_OPTIONS 1 // ---------- ICMP options ---------- #define ICMP_TTL 255 // ---------- RAW options ---------- // ---------- DHCP options ---------- #define LWIP_DHCP 0 // ---------- AUTOIP options ---------- // ---------- SNMP options ---------- // ---------- IGMP options ---------- // ---------- DNS options ----------- // ---------- UDP options ---------- #define LWIP_UDP 1 #define UDP_TTL 255 // ---------- TCP options ---------- #define LWIP_TCP 1 #define TCP_TTL 255 #define TCP_WND 16 * 1024 #define TCP_MAXRTX 12 #define TCP_SYNMAXRTX 4 #define TCP_QUEUE_OOSEQ 1 #define TCP_MSS 1476 #define TCP_SND_BUF 32 * 1024 #define TCP_SND_QUEUELEN 2 * TCP_SND_BUF/TCP_MSS //
//#define LWIP_CALLBACK_API 1 // ---------- Pbuf options ---------- #define PBUF_LINK_HLEN 16 #define PBUF_POOL_BUFSIZE 1536 // ---------- Network Interfaces options ---------- // ---------- LOOPIF options ---------- // ---------- Thread options ---------- #define TCPIP_THREAD_STACKSIZE 1024 #define TCPIP_MBOX_SIZE 16 #define DEFAULT_UDP_RECVMBOX_SIZE 4 #define DEFAULT_TCP_RECVMBOX_SIZE 4 // ---------- Sequential layer options ---------- // ---------- Socket options ---------- #define LWIP_SO_RCVTIMEO 1 Thanks! Bob |
[Prev in Thread] | Current Thread | [Next in Thread] |