Skip to content

Commit e47fb97

Browse files
committed
Final fixed.
Changed logo text of control info. Message proceeding now understands signed numbers. Fixed reconnection select.
1 parent 218612f commit e47fb97

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

client/MainConsole.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <errno.h>
1010
#include <unistd.h>
11+
#include <limits>
1112

1213
#include "SessionClient.hpp"
1314
#include "SessionTcp.hpp"
@@ -70,22 +71,18 @@ namespace simpleApp
7071
delete currentSession;
7172
currentSession = nullptr;
7273
}
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;
7575
break;
7676

7777
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;
8079
break;
8180
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;
8482
break;
8583
}
8684

87-
// TODO clean stdin
88-
85+
std::cout << " >> " << std::flush;
8986
currentState = newState;
9087
};
9188

@@ -113,8 +110,7 @@ namespace simpleApp
113110

114111
int selectResult = select(largerFd + 1, &fd_in, 0, 0, &tv);
115112

116-
// TODO link with break event
117-
if (selectResult == -1)
113+
if (selectResult == -1 && errno != EINTR)
118114
{
119115
std::cout << std::endl << "Select failed with code " << errno << std::endl;
120116
if (currentSession != nullptr)
@@ -145,7 +141,6 @@ namespace simpleApp
145141
}
146142
}
147143

148-
// Something came to socket without request
149144
if (FD_ISSET(currentSession->getSocket(), &fd_in))
150145
{
151146
auto result = currentSession->proceed();
@@ -189,12 +184,17 @@ namespace simpleApp
189184

190185
if (FD_ISSET(this->breakEventFd, &fd_in))
191186
{
187+
eventfd_t decrement = 1;
188+
eventfd_read(this->breakEventFd, &decrement);
189+
190+
std::cout << std::endl;
191+
192192
if (currentState == console_state::protocol_selection)
193193
isExit = true;
194194
else
195+
{
195196
switchState(console_state::protocol_selection);
196-
197-
std::cout << std::endl;
197+
}
198198

199199
continue;
200200
}

client/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void onBreak(int s)
2121

2222
int main(int argc, char** argv)
2323
{
24-
std::cout << "Welcome to the Simple Client! For exit press Ctrl+C" << std::endl;
24+
std::cout << "Welcome to the Simple Client! Press Ctrl+C to exit or set new connection" << std::endl;
2525

2626
if (simpleApp::set_nonblock(STDIN_FILENO) == -1)
2727
{

server/Server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ namespace simpleApp
321321

322322
std::string msg = "Stop event happened";
323323

324-
if (eventfd_read(this->stopEventFd, static_cast<eventfd_t *>(&decrement)) == -1)
324+
if (eventfd_read(this->stopEventFd, &decrement) == -1)
325325
{
326326
msg += std::string("\nStop event decrementation failed with code ") +
327327
std::to_string(errno) + ". Server will stop anyway";

server/message.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace simpleApp
1212
{
1313
auto msgReceived = std::string(in, len);
1414
bool isFound = false;
15-
unsigned long value = 0;
15+
int value = 0;
1616

17-
const std::regex r("[0123456789]+");
17+
const std::regex r("(\\-|\\+)?[0123456789]+");
1818

1919
for (std::sregex_iterator it = std::sregex_iterator(msgReceived.begin(), msgReceived.end(), r);
2020
it != std::sregex_iterator(); it++)

0 commit comments

Comments
 (0)