sources/main.cpp

changeset 192
94c67ae846fc
parent 190
90bf9049e5eb
equal deleted inserted replaced
191:2e6cbacafdc7 192:94c67ae846fc
70 zfc::Interface iface; 70 zfc::Interface iface;
71 71
72 if (argc == 3) 72 if (argc == 3)
73 iface.connect (argv[1], argv[2]); 73 iface.connect (argv[1], argv[2]);
74 74
75 try 75 for (;;)
76 { 76 {
77 for (;;) 77 fd_set fdset;
78 timeval timeout;
79 timeout.tv_sec = 0;
80 timeout.tv_usec = 250000; // 0.25 seconds
81 FD_ZERO(&fdset);
82 FD_SET(0, &fdset);
83 const int fd = iface.getSession()->getSocket()->file_descriptor;
84 FD_SET(fd, &fdset);
85 ::select(fd + 1, &fdset, nullptr, nullptr, &timeout);
86 bool shouldquit = false;
87 if (FD_ISSET(0, &fdset))
78 { 88 {
79 fd_set fdset; 89 // stdin is ready, what's incoming?
80 int highest = 0; 90 iface.handleInput(&shouldquit);
81 timeval timeout; 91 }
82 timeout.tv_sec = 0; 92 if (shouldquit)
83 timeout.tv_usec = 250000; // 0.25 seconds 93 {
84 FD_ZERO (&fdset); 94 break;
85 FD_SET (0, &fdset); 95 }
86 96 else
87 int fd = iface.getSession()->getSocket()->file_descriptor; 97 {
88 highest = zfc::max (highest, fd);
89 FD_SET (fd, &fdset);
90
91 select (highest + 1, &fdset, nullptr, nullptr, &timeout);
92
93 if (FD_ISSET (0, &fdset))
94 {
95 // stdin is ready, what's incoming?
96 iface.handleInput();
97 }
98
99 iface.getSession()->tick(); 98 iface.getSession()->tick();
100 iface.render(); 99 iface.render();
101 } 100 }
102 } 101 }
103 catch (const zfc::Exitception&) {}
104 102
105 iface.getSession()->disconnect(); 103 iface.getSession()->disconnect();
106 return EXIT_SUCCESS; 104 return EXIT_SUCCESS;
107 } 105 }

mercurial