|
8 | 8 |
|
9 | 9 | #include <errno.h> |
10 | 10 | #include <unistd.h> |
| 11 | +#include <limits> |
11 | 12 |
|
12 | 13 | #include "SessionClient.hpp" |
13 | 14 | #include "SessionTcp.hpp" |
@@ -70,22 +71,18 @@ namespace simpleApp |
70 | 71 | delete currentSession; |
71 | 72 | currentSession = nullptr; |
72 | 73 | } |
73 | | - std::cout << "Select protocol: [u]dp or [t]cp" << std::endl << |
74 | | - " >> " << std::flush; |
| 74 | + std::cout << std::endl << "Select protocol: [u]dp or [t]cp" << std::endl; |
75 | 75 | break; |
76 | 76 |
|
77 | 77 | case console_state::address_input: |
78 | | - std::cout << "Input server IP-address" << std::endl << |
79 | | - " >> " << std::flush; |
| 78 | + std::cout << std::endl << "Input server IP-address" << std::endl; |
80 | 79 | break; |
81 | 80 | case console_state::connected: |
82 | | - std::cout << "Connected. Input message" << std::endl << |
83 | | - " >> " << std::flush; |
| 81 | + std::cout << std::endl << "Connected. Input message" << std::endl; |
84 | 82 | break; |
85 | 83 | } |
86 | 84 |
|
87 | | - // TODO clean stdin |
88 | | - |
| 85 | + std::cout << " >> " << std::flush; |
89 | 86 | currentState = newState; |
90 | 87 | }; |
91 | 88 |
|
@@ -113,8 +110,7 @@ namespace simpleApp |
113 | 110 |
|
114 | 111 | int selectResult = select(largerFd + 1, &fd_in, 0, 0, &tv); |
115 | 112 |
|
116 | | - // TODO link with break event |
117 | | - if (selectResult == -1) |
| 113 | + if (selectResult == -1 && errno != EINTR) |
118 | 114 | { |
119 | 115 | std::cout << std::endl << "Select failed with code " << errno << std::endl; |
120 | 116 | if (currentSession != nullptr) |
@@ -145,7 +141,6 @@ namespace simpleApp |
145 | 141 | } |
146 | 142 | } |
147 | 143 |
|
148 | | - // Something came to socket without request |
149 | 144 | if (FD_ISSET(currentSession->getSocket(), &fd_in)) |
150 | 145 | { |
151 | 146 | auto result = currentSession->proceed(); |
@@ -189,12 +184,17 @@ namespace simpleApp |
189 | 184 |
|
190 | 185 | if (FD_ISSET(this->breakEventFd, &fd_in)) |
191 | 186 | { |
| 187 | + eventfd_t decrement = 1; |
| 188 | + eventfd_read(this->breakEventFd, &decrement); |
| 189 | + |
| 190 | + std::cout << std::endl; |
| 191 | + |
192 | 192 | if (currentState == console_state::protocol_selection) |
193 | 193 | isExit = true; |
194 | 194 | else |
| 195 | + { |
195 | 196 | switchState(console_state::protocol_selection); |
196 | | - |
197 | | - std::cout << std::endl; |
| 197 | + } |
198 | 198 |
|
199 | 199 | continue; |
200 | 200 | } |
|
0 commit comments