Reputation: 357
I'm using LwIP with FreeRTOS. My project is based on the example on this URL FreeRTOS with LwIP project. I'm also using LPC1769 with LPCXpresso version 6. CMSIS version 2.
I'm using LwIP to stream MP3 files with a UDP socket. The transfer has a nice speed but the thing is that sometimes lwip_recvfrom blocks after thousands of operations. I can never see the timeout condition. I think I'm doing something wrong.
The followed steps are:
int socket = lwip_socket(AF_INET, SOCK_DGRAM, 0);
if(lwip_setsockopt( socket,
SOL_SOCKET,
SO_RCVTIMEO,
(int)timeoutTimeInMiliSeconds,
sizeof(int)) == -1)
{
return -1;
}
....
if(lwip_bind(protocolConfig.socket,
(struct sockaddr *)&sLocalAddr,
sizeof(sLocalAddr)) == -1)
{
return -1;
}
bytesWritten = lwip_sendto( socket,
transmitBuffer,
transmitBufferIndex,
0,
(struct sockaddr *)&sDestAddr,
sizeof(sDestAddr));
.....
bytesReceived = lwip_recvfrom( socket,
receptionBuffer,
receptionBufferSize,
0,
NULL,
NULL);
if(bytesReceived < 0)
{
//Error stuff, this condition is never reached.
}
Somebody knows what's wrong here?
Upvotes: 2
Views: 6914
Reputation: 1
Since you are using SO_RCVTIMEO
for lwip_setsockopt
, make sure that in the file lwipopts.h
you make sure you add this line:
#define LWIP_SO_RCVTIMEO 1
Otherwise, the lwip_recvfrom()
function will be blocking still.
To go along with what user xryl669 said, I'd recommend using struct timeval
instead of an int
.
In other words:
struct timeval read_timeout;
read_timeout.tv_sec = 1; // 1 sec timeout
read_timeout.tv_usec = 0;
int sock_fd = lwip_socket(AF_INET, SOCK_DGRAM, 0);
lwip_setsockopt( sock_fd, SOL_SOCKET, SO_RCVTIMEO, &read_timeout, sizeof(read_timeout) );
I've tested this on a Xilinx Zynq running FreeRTOS 10, and using one of the sample LWIP templates in Vitis as my starting point.
Upvotes: 0
Reputation: 357
Problem solved.
lwip_setsockopt has this prototype:
int lwip_setsockopt(int socket, int level, int option_name,const void *option_value, socklen_t option_len);
And I was sending by copy the value of option_value.
The timeout is working fine.
Upvotes: 2