sources/main.cpp

changeset 27
089e37c0887e
parent 24
e651d02802c0
child 30
21fba5183768
equal deleted inserted replaced
26:24c7b804c99f 27:089e37c0887e
33 #include "main.h" 33 #include "main.h"
34 #include "network/rconsession.h" 34 #include "network/rconsession.h"
35 #include "huffman/huffman.h" 35 #include "huffman/huffman.h"
36 #include "interface.h" 36 #include "interface.h"
37 37
38 static bool g_shouldExit = false;
39
38 // ------------------------------------------------------------------------------------------------- 40 // -------------------------------------------------------------------------------------------------
39 // 41 //
40 FUNCTION 42 FUNCTION
41 main (int argc, char* argv[]) -> int 43 main (int argc, char* argv[]) -> int
42 { 44 {
43 HUFFMAN_Construct(); 45 HUFFMAN_Construct();
44 Interface::initialize(); 46 Interface::initialize();
45 47
46 for (;;) 48 try
47 { 49 {
48 fd_set fdset; 50 for (;;)
49 int highest = 0; 51 {
50 timeval timeout; 52 if (g_shouldExit)
51 timeout.tv_sec = 0; 53 break;
52 timeout.tv_usec = 250000; // 0.25 seconds
53 FD_ZERO (&fdset);
54 FD_SET (0, &fdset);
55 RCONSession* session = RCONSession::get_session();
56 54
57 if (session) 55 fd_set fdset;
58 { 56 int highest = 0;
59 int fd = session->socket()->file_descriptor(); 57 timeval timeout;
60 highest = max (highest, fd); 58 timeout.tv_sec = 0;
61 FD_SET (fd, &fdset); 59 timeout.tv_usec = 250000; // 0.25 seconds
60 FD_ZERO (&fdset);
61 FD_SET (0, &fdset);
62 RCONSession* session = RCONSession::get_session();
63
64 if (session)
65 {
66 int fd = session->socket()->file_descriptor();
67 highest = max (highest, fd);
68 FD_SET (fd, &fdset);
69 }
70
71 select (highest + 1, &fdset, nullptr, nullptr, &timeout);
72
73 if (FD_ISSET (0, &fdset))
74 // stdin is ready, what's incoming?
75 Interface::handle_input();
76
77 if (session)
78 session->tick();
79
80 Interface::render();
62 } 81 }
82 }
83 catch (const Exitception&) {}
63 84
64 select (highest + 1, &fdset, nullptr, nullptr, &timeout); 85 if (RCONSession::get_session())
65 86 RCONSession::get_session()->disconnect();
66 if (FD_ISSET (0, &fdset))
67 // stdin is ready, what's incoming?
68 Interface::handle_input();
69
70 if (session)
71 session->tick();
72
73 Interface::render();
74 }
75 87
76 return EXIT_SUCCESS; 88 return EXIT_SUCCESS;
77 } 89 }
90
91 // -------------------------------------------------------------------------------------------------
92 //
93 FUNCTION
94 request_exit() -> void
95 {
96 g_shouldExit = true;
97 }

mercurial