/** * * @File : exo_07.cxx * * @Author : A. B. Dragut * * @Synopsis : attente sur un événement venu du clavier ou d'un "timeout". * **/ #include #include #include #include // getdtablesize() #include // fd_set #include "nsSysteme.h" #include "CExc.h" using namespace nsSysteme; using namespace std; int main(int argc, char * argv []) { try { if (1 != argc) throw CExc ("main()",string ("Usage : ") + argv [0]); const int CstNbMax = ::getdtablesize (); ::fd_set MaskRead; FD_ZERO (&MaskRead); struct timeval TimeInit = {5,0}; for (int i = 6; --i; ) { struct timeval Time (TimeInit); FD_SET (0, & MaskRead); if (Select (CstNbMax, & MaskRead, 0, 0, & Time)) { char c; cin.get(c); // on ne veut pas lire les =carriage return cin.ignore(std::numeric_limits::max(), '\n'); // sur Mac la struct timeval ne change pas don affichage avec des delai=0 cout << c << " : caractere lu au bout d'un delai de " << TimeInit.tv_sec + ((double)TimeInit.tv_usec/1000000) - (Time.tv_sec + ((double)Time.tv_usec/1000000)) << endl; } else cout << "timeout atteint" << endl; } return 0; } catch (const CExc & Exc) { cerr <