About how to maintain errno for each task

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

About how to maintain errno for each task

跳至解决方案
624 次查看
atm2024
Contributor III

Hi,

Multiple tasks are communicating with lwIP at the same time.

Each task sets lwip_setsockopt() to handle response timeout.

 

> struct timeval tv;

> tv.tv_sec = RECV_TIMEOUT_MSEC / 1000;

> tv.tv_usec = (RECV_TIMEOUT_MSEC % 1000) * 1000;

> lwip_setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));

 

Each task uses lwip_recv(), lwip_recvfrom(), and lwip_select() to receive data, but timeouts cannot be determined from the return values.

For single task, I can determine timeout by checking errno.

However, since errno is a common global variable, in the case of multitasking, it is not guaranteed which task the result is.

 

In order to maintain errno for each task, is there no other way than to prepare errno for the number of tasks and modify all the places where errno is set?

 

I appreciate your help.

0 项奖励
回复
1 解答
530 次查看
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @atm2024,

I'm afraid there isn't really another proper way of doing this. I would recommend you try using this method, and let us know if you experience further issues.

BR,
Edwin.

在原帖中查看解决方案

0 项奖励
回复
3 回复数
588 次查看
gusarambula
NXP TechSupport
NXP TechSupport

Hello @atm2024 ,

Would you please let us know which MCU or NXP board you are using?

Regards,
Gustavo

0 项奖励
回复
558 次查看
atm2024
Contributor III
Thank you for your reply, Gustavo.
I'm using the MIMXRT1064-EVK with version 2.15.000 of the SDK.
I'm trying to build an application that uses FreeRTOS, lwip stack and mbedtls stack.
 
I tried adding "int errno;" to "struct lwip_sock".
And I newly defined "set_errno_each()" and "get_errno_each()".
 
------------------------------------------
/lwip/src/include/lwip/priv/sockets_priv.h
------------------------------------------
struct lwip_sock {
...
#ifdef MODIFY_LWIP_SOCK
int errno;
#endif
};
 
#ifdef MODIFY_LWIP
#define set_errno_each(err, errno) (errno) = (err)
#endif
 
------------------------------------------
/lwip/src/include/lwip/sockets.h
------------------------------------------
#ifdef MODIFY_LWIP_SOCK
int get_errno_each(int fd);
#endif
 
------------------------------------------
/lwip/src/api/sockets.c
------------------------------------------
#ifdef MODIFY_LWIP_SOCK
int get_errno_each(int fd)
{
struct lwip_sock *sock = get_socket(fd);
if (!sock) {
return -1;
}
return sock->errno;
}
#endif
 
This change seems to have generally worked.
 
However, there are cases where the lwip_sock object does not exist in the traditional errno setting location, in which case sock->errno also does not exist, so it cannot always be referenced.
This modify is not very smart.
Is there a better way?
 
I appreciate your help.
0 项奖励
回复
531 次查看
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @atm2024,

I'm afraid there isn't really another proper way of doing this. I would recommend you try using this method, and let us know if you experience further issues.

BR,
Edwin.

0 项奖励
回复