About how to maintain errno for each task

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

About how to maintain errno for each task

ソリューションへジャンプ
1,555件の閲覧回数
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 解決策
1,461件の閲覧回数
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 返答(返信)
1,519件の閲覧回数
gusarambula
NXP TechSupport
NXP TechSupport

Hello @atm2024 ,

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

Regards,
Gustavo

0 件の賞賛
返信
1,489件の閲覧回数
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 件の賞賛
返信
1,462件の閲覧回数
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 件の賞賛
返信