Ctrl +C shutdown for a blocking call
Hello,
Inside my loop
while(ros::ok())
{
// do blocking recvfrom socket
// receives data from socket
recvfrom(s, _buf, buf_size_, 0, (struct sockaddr *) &si_other, &slen);
...
ros::spinOnce();
}
This code work perfectly and the ROS_INFO shows that is receives data from socket port correctly. NOTE here the incoming data is outside ros node. But when I exit using Ctrl+C. The node does not exit. The result is I have to force shutdown. This causes my port to connected. netstat shows the port is still in use. however rosnode list shows that the node has shutdown. This is likely because the code is stuck at the blocking call recvfrom. Any suggestion to overcome this ?
My question is similar to
http://answers.ros.org/question/31570...
But the suggestion spinOnce didnt help
You probably need to set a timeout on your socket so that it exits from recvfrom when no data is received, and eventually has the opportunity to exit the main loop.
Is that the only way ? or rather the recommended way ?