Add guts of 'EchoServer' state machine. (Currently unused.)

git-svn-id: svn+ssh://oldsvn/home/mlalondesvn/svn/cral@121 3ee9b42a-b53c-0410-a25e-f0b6218d5d5b
master
follower 17 years ago
parent 11551d3b61
commit 43c20bf422

@ -423,6 +423,7 @@ class EchoServer {
public:
EchoServer(int port);
void next(); // TODO: Return something useful?
private:
NetworkConnection _connection; // TODO: Make public?
@ -439,6 +440,41 @@ EchoServer::EchoServer(int port) : _connection (NetworkConnection(port)) {
_connection.listen(); // TODO: We should be using Network.listen(...) here and in initialisation list.
}
void EchoServer::next() {
/*
*/
// TODO: Use better state machine implementation?
if (_state == ECHO_CONNECT_WAIT) {
if (_connection.isConnected()) {
_state = ECHO_CONNECTED;
} else {
// Keep waiting
}
} else if (_state == ECHO_CONNECTED) {
if (_connection.available()) {
_connection.print(_connection.read());
} else if (!_connection.isConnected()) {
// Data finished and client disconnected
_state == ECHO_CLOSE;
}
} else if (_state == ECHO_CLOSE) {
_connection.close();
_state = ECHO_HALT;
} else if (_state == ECHO_HALT) {
// Do nothing
} else {
// Unknown state, do nothing.
}
}
/* ----------------------- */

Loading…
Cancel
Save