hi, i migrated from mqx 4.1 to mqx4.2, i use CW 10.6 and frmk64f.
in my application i used the RTCS_selectset() functionand it work properly; i read in the documentation of the rtcs that is recommended the use of the select() function. i seen the example and i try to use it with some changes. everything is ok till i use the RTCS_FD_CLR() function.
my application comunicates with my pc so i use a set of socket and i must check the activity of those sockets. i'm inside a while cycle and sometimes i need to add or remove a socket from the set. adding socket happens correctly but when i try to remove the socket from the set i have some problems:
-if i use the RTCS_FD_CLR() function, when the cycle come again on the select() function it return a error 0x1716 that in rtcs_err.h is RTCSERR_SOCK_EBADF. I seen that is a error returned when the select() function check if the socket is in the socket set.
if i do not use the RTCS_FD_CLR(), the select() function return the same error.
so my question is: there is a way to use correctly the RTCS_FD_CLR() function? or there is a way to know if i use correctly this function?
now i'm trying to clear all the set and i add again all the socket i need.
a very semplified version of my cycle is:
while(1){
err=select(active_socket_number,&sock_set,NULL,NULL, 0);
...
else{
if(RTCS_FD_ISSET(serv_sock, &sock_set)){
accept(...);
RTCS_FD_SET(sock,&sock_set);
active_socket_number++;
...
} else {
rx_count=recv(sock,buf,buf_size);
if (rx_count==RTCS_ERROR) {
RTCS_FD_CLR(sock,&sock_set)
closesock(sock);
active_socket_number--;
...
}
...
}
...
}
ps: i use multiple select() function of different set of sockets in different task. But those different set may contain the same socket. can this be the problem?
解決済! 解決策の投稿を見る。
select() changes the sock_set when it returns. Therefore you must to re-fill sock_set before select() each time it is called - in every while cycle.
while(1)
{
RTCS_FD_ZERO(&sock_set);
RTCS_FD_SET(sock1, &sock_set);
RTCS_FD_SET(sock2, &sock_set);
select(...)
}
You can have two sets. In one set you could keep the active sockets (add a connected client, remove disconnect client). And then before select() you just copy this set to another which is given to select():
while(1)
{
memcpy(&sock_set, &sock_set_init, sizeof(rtcs_fd_set));
select(..&sock_set.)
RTCS_FD_SET(client_sock, &sock_set_init); /* add established socket */
RTCS_FD_CLEAR(client_sock, sock_set_init); /* remove closed socket */
}
select() changes the sock_set when it returns. Therefore you must to re-fill sock_set before select() each time it is called - in every while cycle.
while(1)
{
RTCS_FD_ZERO(&sock_set);
RTCS_FD_SET(sock1, &sock_set);
RTCS_FD_SET(sock2, &sock_set);
select(...)
}
You can have two sets. In one set you could keep the active sockets (add a connected client, remove disconnect client). And then before select() you just copy this set to another which is given to select():
while(1)
{
memcpy(&sock_set, &sock_set_init, sizeof(rtcs_fd_set));
select(..&sock_set.)
RTCS_FD_SET(client_sock, &sock_set_init); /* add established socket */
RTCS_FD_CLEAR(client_sock, sock_set_init); /* remove closed socket */
}
thank you martin!
i resolved using one select() for one socket! but your solution is better! i keep in mind for the next time!
have a nice day!