More work on client and server

This commit is contained in:
2021-11-11 16:23:11 -05:00
parent caa5bab9d3
commit c1c0b02926
9 changed files with 103 additions and 21 deletions

View File

@@ -62,6 +62,8 @@ public:
}
void abandon_server() {
stdostream() << "Abandoning server." << std::endl;
// Put the world model back into a known-good state.
set_initial_state();
@@ -189,10 +191,11 @@ public:
}
void change_actor_id(int64_t actor_id) {
stdostream() << "Actor ID changing: " << actor_id << std::endl;
print_channeler_.reset();
actor_id_ = actor_id;
}
void receive_ack_from_server(StreamBuffer *sb) {
// An ack is just a single byte, so there's nothing left to read.
if (unack_.empty()) {
@@ -208,7 +211,7 @@ public:
void receive_diff_from_server(StreamBuffer *sb) {
world_to_synchronous();
try {
int nactor = world_->patch_everything(sb);
int64_t nactor = world_->patch_everything(sb);
if (nactor != actor_id_) change_actor_id(nactor);
} catch (const StreamEof &seof) {
abandon_server();
@@ -260,10 +263,18 @@ public:
stdostream() << "Server closed connection " << channel_->error() << std::endl;
abandon_server();
} else {
while (receive_message_from_server(channel_->in()));
while (true) {
if (!receive_message_from_server(channel_->in())) break;
if (channel_ == nullptr) break;
}
world_to_asynchronous();
}
}
// Channel print statements.
if (print_channeler_.channel(world_->get_printbuffer(actor_id_), stdostream())) {
send_invocation(print_channeler_.invocation(actor_id_));
}
}
};