Skip to content

Commit 218612f

Browse files
committed
Minor fixes.
Fixed 'select' timer on client-side. Fixed session state on client-side errors. Fixed SessionServer class members initialization order.
1 parent 02a50ad commit 218612f

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

client/MainConsole.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,13 @@ namespace simpleApp
5555
std::cout << "Break event is not set" << std::endl;
5656
return -1;
5757
}
58-
59-
timeval tv;
60-
61-
tv.tv_sec = 5;
62-
tv.tv_usec = 0;
6358

6459
bool isExit = false;
6560
SessionClient * currentSession = nullptr;
6661
console_state currentState;
6762

6863
auto switchState = [&currentState, &currentSession](console_state newState)
6964
{
70-
// TODO
71-
72-
// TODO STDIN clean up
73-
7465
switch (newState)
7566
{
7667
case console_state::protocol_selection:
@@ -93,6 +84,8 @@ namespace simpleApp
9384
break;
9485
}
9586

87+
// TODO clean stdin
88+
9689
currentState = newState;
9790
};
9891

@@ -112,12 +105,18 @@ namespace simpleApp
112105
auto sessionSocket = currentSession->getSocket();
113106
largerFd = sessionSocket > largerFd ? sessionSocket : largerFd;
114107
}
115-
108+
109+
timeval tv;
110+
111+
tv.tv_sec = 5;
112+
tv.tv_usec = 0;
113+
116114
int selectResult = select(largerFd + 1, &fd_in, 0, 0, &tv);
117115

116+
// TODO link with break event
118117
if (selectResult == -1)
119118
{
120-
std::cout << "Select failed with code " << errno;
119+
std::cout << std::endl << "Select failed with code " << errno << std::endl;
121120
if (currentSession != nullptr)
122121
delete currentSession;
123122
return -1;
@@ -140,7 +139,7 @@ namespace simpleApp
140139
else
141140
std::cout << std::endl << std::flush;
142141

143-
switchState(console_state::address_input);
142+
switchState(console_state::protocol_selection);
144143

145144
continue;
146145
}
@@ -195,6 +194,8 @@ namespace simpleApp
195194
else
196195
switchState(console_state::protocol_selection);
197196

197+
std::cout << std::endl;
198+
198199
continue;
199200
}
200201

@@ -312,18 +313,14 @@ namespace simpleApp
312313

313314
switchState(console_state::protocol_selection);
314315
}
315-
}
316-
317-
// TODO clear cin
316+
}
318317
}
319318
}
320319

321320
if (currentSession != nullptr)
322321
{
323322
delete currentSession;
324323
}
325-
326-
// TODO clear cin
327324

328325
return 0;
329326
}

server/SessionServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace simpleApp
99
{
10-
SessionServer::SessionServer(int epollfd, std::string name) : epollfd(epollfd), _name(name), Session()
10+
SessionServer::SessionServer(int epollfd, std::string name) : Session(), epollfd(epollfd), _name(name)
1111
{
1212

1313
}

server/SessionServer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace simpleApp
2424
std::string getName();
2525

2626
protected:
27-
std::string _name;
2827
int epollfd;
28+
std::string _name;
2929

3030
SessionServer(int epollfd, std::string name = "");
3131

0 commit comments

Comments
 (0)