You can use following constellation (this is not the complete solution, but just algorithm):
while(1) {
FD_ZERO(&rdfs);
FD_SET(s, &rdfs);
tv.tv_sec = 0;
tv.tv_usec = 10000; // microseconds
rc = select(s + 1, &rdfs, NULL, NULL, &tv);
// rc == 0 - timeout
if (!rc) {
// write your CAN frame
}
if (FD_ISSET(s, &rdfs)) {
// read CAN frames
}
}
See man select for more information and how to handle return value.