Remove the concept of the 'stdio channel' from class DrivenEngine
This commit is contained in:
@@ -37,7 +37,9 @@ DrivenEngineInitializerReg::DrivenEngineInitializerReg(DrivenEngineInitializer f
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int DrivenEngine::find_unused_chid() {
|
int DrivenEngine::find_unused_chid() {
|
||||||
// Note: channel ID zero is special, it is never reused.
|
// Note: channel ID zero is never used. Channel ID 0 used to be
|
||||||
|
// reserved for the stdio channel. When we eliminated the stdio
|
||||||
|
// channel, we blocked off ID 0 permanently.
|
||||||
for (int i = 0; i < DRV_MAX_CHAN; i++) {
|
for (int i = 0; i < DRV_MAX_CHAN; i++) {
|
||||||
int id = next_unused_chid_++;
|
int id = next_unused_chid_++;
|
||||||
if (next_unused_chid_ == DRV_MAX_CHAN) next_unused_chid_ = 1;
|
if (next_unused_chid_ == DRV_MAX_CHAN) next_unused_chid_ = 1;
|
||||||
@@ -48,6 +50,7 @@ int DrivenEngine::find_unused_chid() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Channel *DrivenEngine::get_chid(int chid) const {
|
Channel *DrivenEngine::get_chid(int chid) const {
|
||||||
|
assert(chid != 0);
|
||||||
assert(unsigned(chid) < DRV_MAX_CHAN);
|
assert(unsigned(chid) < DRV_MAX_CHAN);
|
||||||
assert(channels_[chid].get() != nullptr);
|
assert(channels_[chid].get() != nullptr);
|
||||||
return channels_[chid].get();
|
return channels_[chid].get();
|
||||||
@@ -160,10 +163,6 @@ SharedChannel DrivenEngine::new_incoming_channel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedChannel DrivenEngine::get_stdio_channel() {
|
|
||||||
return stdio_channel_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrivenEngine::set_visible_world_and_actor(World *w, int64_t id) {
|
void DrivenEngine::set_visible_world_and_actor(World *w, int64_t id) {
|
||||||
visible_world_ = w;
|
visible_world_ = w;
|
||||||
visible_actor_id_ = id;
|
visible_actor_id_ = id;
|
||||||
@@ -180,8 +179,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);
|
|
||||||
channels_[0] = stdio_channel_;
|
|
||||||
rescan_lua_source_ = false;
|
rescan_lua_source_ = false;
|
||||||
clock_ = 0.0;
|
clock_ = 0.0;
|
||||||
have_prints_ = false;
|
have_prints_ = false;
|
||||||
|
|||||||
@@ -196,16 +196,6 @@ public:
|
|||||||
//
|
//
|
||||||
SharedChannel new_incoming_channel();
|
SharedChannel new_incoming_channel();
|
||||||
|
|
||||||
// Obtain the stdio channel. There is only one stdio channel.
|
|
||||||
//
|
|
||||||
// DRIVER: the stdio channel is created automatically when the DrivenEngine
|
|
||||||
// is created. Stdio should be connected to a console which is in
|
|
||||||
// line-at-a-time mode. The driver is responsible for relaying data from
|
|
||||||
// the console into the stdio channel using drv_peek_outgoing,
|
|
||||||
// drv_sent_outgoing, drv_recv_incoming.
|
|
||||||
//
|
|
||||||
SharedChannel get_stdio_channel();
|
|
||||||
|
|
||||||
// Set the flag to rescan the lua source directory. The lua source
|
// Set the flag to rescan the lua source directory. The lua source
|
||||||
// directory is read once, automatically, at engine creation time.
|
// directory is read once, automatically, at engine creation time.
|
||||||
// If you want to read it again, you must trigger a rescan.
|
// If you want to read it again, you must trigger a rescan.
|
||||||
@@ -300,7 +290,6 @@ private:
|
|||||||
private:
|
private:
|
||||||
SharedChannel channels_[DRV_MAX_CHAN];
|
SharedChannel channels_[DRV_MAX_CHAN];
|
||||||
int next_unused_chid_;
|
int next_unused_chid_;
|
||||||
SharedChannel stdio_channel_;
|
|
||||||
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_;
|
||||||
|
|||||||
@@ -6,19 +6,15 @@
|
|||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
static void write_closed_message(Channel *ch, StreamBuffer *out) {
|
static void write_closed_message(Channel *ch) {
|
||||||
eng::ostringstream oss;
|
util::dprint("Chan ", ch->chid(), " closed [", ch->error(), "]\n");
|
||||||
oss << "Chan " << ch->chid() << " closed [" << ch->error() << "]\n";
|
|
||||||
out->write_bytes(oss.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dump_lines(StreamBuffer *in, StreamBuffer *out, int chid) {
|
static void dump_lines(StreamBuffer *in, int chid) {
|
||||||
while (true) {
|
while (true) {
|
||||||
eng::string l = in->readline();
|
eng::string l = in->readline();
|
||||||
if (l == "") break;
|
if (l == "") break;
|
||||||
eng::ostringstream oss;
|
util::dprint("Chan ", chid, ": ", l);
|
||||||
oss << "Chan " << chid << ": " << l;
|
|
||||||
out->write_bytes(oss.str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,13 +30,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void event_update() override {
|
virtual void event_update() override {
|
||||||
SharedChannel stdioch = get_stdio_channel();
|
|
||||||
dump_lines(stdioch->in(), stdioch->out(), 0);
|
|
||||||
eng::vector<SharedChannel> keep;
|
eng::vector<SharedChannel> keep;
|
||||||
for (SharedChannel &ch : channels_) {
|
for (SharedChannel &ch : channels_) {
|
||||||
dump_lines(ch->in(), stdioch->out(), ch->chid());
|
dump_lines(ch->in(), ch->chid());
|
||||||
if (ch->closed()) {
|
if (ch->closed()) {
|
||||||
write_closed_message(ch.get(), stdioch->out());
|
write_closed_message(ch.get());
|
||||||
} else {
|
} else {
|
||||||
keep.emplace_back(std::move(ch));
|
keep.emplace_back(std::move(ch));
|
||||||
}
|
}
|
||||||
@@ -60,13 +54,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void event_update() override {
|
virtual void event_update() override {
|
||||||
SharedChannel stdioch = get_stdio_channel();
|
|
||||||
dump_lines(stdioch->in(), stdioch->out(), 0);
|
|
||||||
eng::vector<SharedChannel> keep;
|
eng::vector<SharedChannel> keep;
|
||||||
for (SharedChannel &ch : channels_) {
|
for (SharedChannel &ch : channels_) {
|
||||||
dump_lines(ch->in(), stdioch->out(), ch->chid());
|
dump_lines(ch->in(), ch->chid());
|
||||||
if (ch->closed()) {
|
if (ch->closed()) {
|
||||||
write_closed_message(ch.get(), stdioch->out());
|
write_closed_message(ch.get());
|
||||||
} else {
|
} else {
|
||||||
keep.emplace_back(std::move(ch));
|
keep.emplace_back(std::move(ch));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user