linux - Select in C, why does it fail? -


i'm reviewing code in c select(2) function. in code, select function should return number different 0 when of set of 2 sockets it's ready. fails find file descriptor ready though sockets declared before select , when netstat --listen 1 of sockets (cmd_socket) listening on specified port. i've tried forcing different timeouts , assume fd_setsize ok because code used work in machine. wrong? code:

 // program sockets intialization int cmd_sock = create_and_bind_socket(cmd_port_property(0,get) ,&src_addr); mc_sock = create_and_bind_socket(mcast_port_property(0,get), &mc_addr);  join_multicast_group(mc_sock,mc_addr_str, &mc_req);   int recv_len = 0; int childs = 0;  struct timeval tv; struct timeval *ptv = &tv;  if (!timeout) {    ptv = null;  } else {    ptv->tv_sec = timeout;   ptv->tv_usec = 0;  }  fd_set readfds, safe; fdmax = mc_sock;  // add multicast , unicast sockets set fd_zero(&readfds); fd_set(cmd_sock, &readfds); fd_set(mc_sock, &readfds);  safe = readfds;  // wait until socket on set ready read  while(select (fd_setsize,&readfds,null,null,ptv))  {  

actually, first argument select(2) the highest-numbered file descriptor in of 3 sets, plus 1, not fd_setsize, number of bytes fd_set takes.

then 0 return select(2) means timeout expired. check if have data on wire, use tcpdump(1) or wireshark.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -