Eliminate stdostream (finally, that was awful.)
This commit is contained in:
@@ -66,35 +66,38 @@ static DrivenEngine *make_engine(std::string_view kind) {
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// The stdostream
|
// A std::ostream that sends its output to a StreamBuffer.
|
||||||
|
//
|
||||||
|
// This is not currently used so it's commented out. But if it's
|
||||||
|
// needed, it works fine: it can be ressurected.
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class StreamBufferWriter : public std::streambuf, public eng::opnew {
|
// class StreamBufferWriter : public std::streambuf, public eng::opnew {
|
||||||
private:
|
// private:
|
||||||
StreamBuffer *target_;
|
// StreamBuffer *target_;
|
||||||
public:
|
// public:
|
||||||
StreamBufferWriter(StreamBuffer *t) : target_(t) {}
|
// StreamBufferWriter(StreamBuffer *t) : target_(t) {}
|
||||||
|
|
||||||
virtual int_type overflow(int_type c) {
|
// virtual int_type overflow(int_type c) {
|
||||||
if (c != EOF) {
|
// if (c != EOF) {
|
||||||
target_->write_uint8(c);
|
// target_->write_uint8(c);
|
||||||
}
|
// }
|
||||||
return c;
|
// return c;
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
class StreamBufferOStream : public std::ostream, public eng::opnew {
|
// class StreamBufferOStream : public std::ostream, public eng::opnew {
|
||||||
private:
|
// private:
|
||||||
StreamBufferWriter writer_;
|
// StreamBufferWriter writer_;
|
||||||
public:
|
// public:
|
||||||
StreamBufferOStream(StreamBuffer *t) : std::ostream(nullptr), writer_(t) {
|
// StreamBufferOStream(StreamBuffer *t) : std::ostream(nullptr), writer_(t) {
|
||||||
rdbuf(&writer_);
|
// rdbuf(&writer_);
|
||||||
}
|
// }
|
||||||
virtual ~StreamBufferOStream() {
|
// virtual ~StreamBufferOStream() {
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -186,7 +189,6 @@ void DrivenEngine::stop_driver() {
|
|||||||
DrivenEngine::DrivenEngine() {
|
DrivenEngine::DrivenEngine() {
|
||||||
next_unused_chid_ = 1;
|
next_unused_chid_ = 1;
|
||||||
stdio_channel_ = eng::make_shared<Channel>(this, 0, 0, "", false);
|
stdio_channel_ = eng::make_shared<Channel>(this, 0, 0, "", false);
|
||||||
stdostream_.reset(new StreamBufferOStream(stdio_channel_->out()));
|
|
||||||
channels_[0] = stdio_channel_;
|
channels_[0] = stdio_channel_;
|
||||||
rescan_lua_source_ = false;
|
rescan_lua_source_ = false;
|
||||||
clock_ = 0.0;
|
clock_ = 0.0;
|
||||||
|
|||||||
@@ -206,10 +206,6 @@ public:
|
|||||||
//
|
//
|
||||||
SharedChannel get_stdio_channel();
|
SharedChannel get_stdio_channel();
|
||||||
|
|
||||||
// Obtain the output buffer of the stdio channel as an ostream.
|
|
||||||
//
|
|
||||||
std::ostream &stdostream() { return *stdostream_; }
|
|
||||||
|
|
||||||
// Set the prompt for the console.
|
// Set the prompt for the console.
|
||||||
//
|
//
|
||||||
void set_console_prompt(const eng::string &prompt);
|
void set_console_prompt(const eng::string &prompt);
|
||||||
@@ -304,7 +300,6 @@ private:
|
|||||||
SharedChannel channels_[DRV_MAX_CHAN];
|
SharedChannel channels_[DRV_MAX_CHAN];
|
||||||
int next_unused_chid_;
|
int next_unused_chid_;
|
||||||
SharedChannel stdio_channel_;
|
SharedChannel stdio_channel_;
|
||||||
std::unique_ptr<std::ostream> stdostream_;
|
|
||||||
eng::vector<SharedChannel> accepted_channels_;
|
eng::vector<SharedChannel> accepted_channels_;
|
||||||
eng::vector<uint32_t> new_outgoing_;
|
eng::vector<uint32_t> new_outgoing_;
|
||||||
eng::vector<uint32_t> listen_ports_;
|
eng::vector<uint32_t> listen_ports_;
|
||||||
|
|||||||
@@ -89,14 +89,10 @@ public:
|
|||||||
double clock = get_clock();
|
double clock = get_clock();
|
||||||
if (clock > last_clock_ + 0.5) {
|
if (clock > last_clock_ + 0.5) {
|
||||||
int ms = eng::memhash();
|
int ms = eng::memhash();
|
||||||
stdostream() << std::fixed << std::setprecision(2) << clock << " " << std::hex << ms << " ";
|
util::dprint(std::fixed, std::setprecision(2), clock, " ", std::hex, ms);
|
||||||
count_++;
|
count_++;
|
||||||
last_clock_ = clock;
|
last_clock_ = clock;
|
||||||
}
|
}
|
||||||
if (count_ == 4) {
|
|
||||||
stdostream() << std::endl;
|
|
||||||
count_ = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -135,15 +135,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void do_syntax_error(std::string_view error) override {
|
virtual void do_syntax_error(std::string_view error) override {
|
||||||
stdostream() << "Syntax error: " << error << std::endl;
|
util::dprint("Syntax error: ", error, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void do_unknown_command(std::string_view name) override {
|
virtual void do_unknown_command(std::string_view name) override {
|
||||||
stdostream() << "Unknown command: " << name << std::endl;
|
util::dprint("Unknown command: ", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void do_view_command() override {
|
virtual void do_view_command() override {
|
||||||
stdostream() << world_->tangibles_near_debug_string(actor_id_, 1000);
|
util::dprint(world_->tangibles_near_debug_string(actor_id_, 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void do_moveto_command(int x, int y) override {
|
virtual void do_moveto_command(int x, int y) override {
|
||||||
@@ -181,7 +181,7 @@ public:
|
|||||||
|
|
||||||
virtual void do_luaprobe_command(std::string_view cmd) override {
|
virtual void do_luaprobe_command(std::string_view cmd) override {
|
||||||
world_to_asynchronous();
|
world_to_asynchronous();
|
||||||
stdostream() << world_->probe_lua_expr(actor_id_, cmd);
|
util::dprint(world_->probe_lua_expr(actor_id_, cmd));
|
||||||
world_to_synchronous();
|
world_to_synchronous();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +210,7 @@ public:
|
|||||||
DebugCollector dbc("");
|
DebugCollector dbc("");
|
||||||
int64_t nactor = world_->patch(sb, &dbc);
|
int64_t nactor = world_->patch(sb, &dbc);
|
||||||
if (nactor != actor_id_) change_actor_id(nactor);
|
if (nactor != actor_id_) change_actor_id(nactor);
|
||||||
dbc.dump(stdostream());
|
// dbc.dump(...);
|
||||||
} catch (const StreamException &sexcept) {
|
} catch (const StreamException &sexcept) {
|
||||||
abandon_server();
|
abandon_server();
|
||||||
return;
|
return;
|
||||||
@@ -271,6 +271,7 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AccessKind::CHANNEL_PRINTS: {
|
case AccessKind::CHANNEL_PRINTS: {
|
||||||
|
// If there's nothing new in the printbuffer, this is very fast.
|
||||||
world_to_asynchronous();
|
world_to_asynchronous();
|
||||||
if (print_channeler_.channel(world_->get_printbuffer(actor_id_), retpk)) {
|
if (print_channeler_.channel(world_->get_printbuffer(actor_id_), retpk)) {
|
||||||
send_invocation(print_channeler_.invocation(actor_id_));
|
send_invocation(print_channeler_.invocation(actor_id_));
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
admin_id_ = master_->create_login_actor();
|
admin_id_ = master_->create_login_actor();
|
||||||
|
|
||||||
// Print out admin ID for debugging purposes.
|
// Print out admin ID for debugging purposes.
|
||||||
stdostream() << "Admin actor id = " << admin_id_ << std::endl;
|
util::dprint("Admin actor id = ", admin_id_);
|
||||||
|
|
||||||
// Enable listening on port 8085 (client connections)
|
// Enable listening on port 8085 (client connections)
|
||||||
listen_port(8085);
|
listen_port(8085);
|
||||||
@@ -75,15 +75,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void do_syntax_error(std::string_view error) override {
|
virtual void do_syntax_error(std::string_view error) override {
|
||||||
stdostream() << "Syntax error: " << error << std::endl;
|
util::dprint("Syntax error: ", error, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void do_unknown_command(std::string_view name) override {
|
virtual void do_unknown_command(std::string_view name) override {
|
||||||
stdostream() << "Unknown command: " << name << std::endl;
|
util::dprint("Unknown command: ", name, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void do_view_command() override {
|
virtual void do_view_command() override {
|
||||||
stdostream() << master_->tangibles_near_debug_string(admin_id_, 1000);
|
util::dprint(master_->tangibles_near_debug_string(admin_id_, 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void do_moveto_command(int x, int y) override {
|
virtual void do_moveto_command(int x, int y) override {
|
||||||
@@ -120,12 +120,12 @@ public:
|
|||||||
|
|
||||||
virtual void do_luaprobe_command(std::string_view cmd) override {
|
virtual void do_luaprobe_command(std::string_view cmd) override {
|
||||||
master_->snapshot();
|
master_->snapshot();
|
||||||
stdostream() << master_->probe_lua_expr(admin_id_, cmd);
|
util::dprint(master_->probe_lua_expr(admin_id_, cmd));
|
||||||
master_->rollback();
|
master_->rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_client(UniqueClient &client) {
|
void delete_client(UniqueClient &client) {
|
||||||
stdostream() << "Client closed: actor id=" << client->actor_id_ << std::endl;
|
util::dprint("Client closed: actor id=", client->actor_id_);
|
||||||
master_->disconnected(client->actor_id_);
|
master_->disconnected(client->actor_id_);
|
||||||
client.reset();
|
client.reset();
|
||||||
}
|
}
|
||||||
@@ -135,7 +135,7 @@ public:
|
|||||||
sb->write_uint8(util::MSG_DIFF);
|
sb->write_uint8(util::MSG_DIFF);
|
||||||
sb->write_uint32(0);
|
sb->write_uint32(0);
|
||||||
int64_t tw_1 = sb->total_writes();
|
int64_t tw_1 = sb->total_writes();
|
||||||
//stdostream() << "Sending diffs to client " << client->actor_id_ << std::endl;
|
// util::dprint("Sending diffs to client ", client->actor_id_);
|
||||||
client->sync_->diff(client->actor_id_, full, master_.get(), sb);
|
client->sync_->diff(client->actor_id_, full, master_.get(), sb);
|
||||||
int64_t tw_2 = sb->total_writes();
|
int64_t tw_2 = sb->total_writes();
|
||||||
sb->overwrite_int32(tw_1, tw_2 - tw_1);
|
sb->overwrite_int32(tw_1, tw_2 - tw_1);
|
||||||
@@ -164,7 +164,7 @@ public:
|
|||||||
delete_client(client);
|
delete_client(client);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//stdostream() << "Invoking: " << inv.debug_string() << std::endl;
|
// util::dprint("Invoking: ", inv.debug_string());
|
||||||
master_->invoke(inv);
|
master_->invoke(inv);
|
||||||
client->channel_->out()->write_uint8(util::MSG_ACK);
|
client->channel_->out()->write_uint8(util::MSG_ACK);
|
||||||
client->channel_->out()->write_uint32(0);
|
client->channel_->out()->write_uint32(0);
|
||||||
@@ -198,13 +198,14 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AccessKind::CHANNEL_PRINTS: {
|
case AccessKind::CHANNEL_PRINTS: {
|
||||||
|
// If there's nothing new in the printbuffer, this is very fast.
|
||||||
if (print_channeler_.channel(master_->get_printbuffer(admin_id_), retpk)) {
|
if (print_channeler_.channel(master_->get_printbuffer(admin_id_), retpk)) {
|
||||||
master_->invoke(print_channeler_.invocation(admin_id_));
|
master_->invoke(print_channeler_.invocation(admin_id_));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
stdostream() << "Invalid event_access: " << int(kind) << std::endl;
|
util::dprint("Invalid event_access: ", int(kind));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,7 +247,7 @@ public:
|
|||||||
// the client model and the server synchronous model are identical.
|
// the client model and the server synchronous model are identical.
|
||||||
client->sync_->create_login_actor();
|
client->sync_->create_login_actor();
|
||||||
clients_.emplace_back(client);
|
clients_.emplace_back(client);
|
||||||
stdostream() << "New client: actor id=" << client->actor_id_ << std::endl;
|
util::dprint("New client: actor id=", client->actor_id_);
|
||||||
} else if (chan->port() == 8080) {
|
} else if (chan->port() == 8080) {
|
||||||
HttpChannel htchan;
|
HttpChannel htchan;
|
||||||
htchan.channel_ = chan;
|
htchan.channel_ = chan;
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ public:
|
|||||||
// Reset the print channeler.
|
// Reset the print channeler.
|
||||||
void reset() { line_ = 0; }
|
void reset() { line_ = 0; }
|
||||||
|
|
||||||
// Copy any new lines from the printbuffer to the stdostream.
|
// Copy any new lines from the printbuffer to the stream buffer.
|
||||||
// Update the current line number. Return true if the printbuffer
|
// Update the current line number. Return true if the printbuffer
|
||||||
// contains any lines that have already been channeled.
|
// contains any lines that have already been channeled.
|
||||||
bool channel(const PrintBuffer *pb, StreamBuffer *sb);
|
bool channel(const PrintBuffer *pb, StreamBuffer *sb);
|
||||||
|
|||||||
Reference in New Issue
Block a user