2020-11-12 14:24:33 -05:00
|
|
|
|
2021-01-22 19:10:47 -05:00
|
|
|
#include "textgame.hpp"
|
2021-10-04 17:45:18 -04:00
|
|
|
#include "driver.hpp"
|
2021-10-08 16:38:10 -04:00
|
|
|
#include "drivenengine.hpp"
|
|
|
|
|
|
|
|
|
|
class TNTest : public DrivenEngine {
|
|
|
|
|
public:
|
|
|
|
|
std::unique_ptr<Channel> chan_;
|
|
|
|
|
virtual void event_init() {
|
|
|
|
|
chan_ = new_outgoing_channel("stanford.edu:80");
|
|
|
|
|
chan_->out()->write_bytes("GET /index.html HTTP/1.1\n\n");
|
|
|
|
|
}
|
|
|
|
|
virtual void event_update() {
|
|
|
|
|
std::string input = get_stdio_channel()->in()->read_entire_contents();
|
|
|
|
|
if (input != "") {
|
|
|
|
|
get_stdio_channel()->out()->write_bytes("stdin: ");
|
|
|
|
|
get_stdio_channel()->out()->write_bytes(input);
|
|
|
|
|
}
|
|
|
|
|
if (chan_ != nullptr) {
|
|
|
|
|
if (chan_->closed()) {
|
|
|
|
|
get_stdio_channel()->out()->write_bytes("Connection closed.\n");
|
|
|
|
|
chan_.reset();
|
|
|
|
|
} else {
|
|
|
|
|
chan_->in()->copy_into(get_stdio_channel()->out());
|
|
|
|
|
chan_->in()->clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-11-12 14:24:33 -05:00
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2021-10-08 16:38:10 -04:00
|
|
|
//TextGame tg;
|
|
|
|
|
TNTest tg;
|
2021-10-04 17:45:18 -04:00
|
|
|
driver_drive(&tg);
|
2020-11-12 14:24:33 -05:00
|
|
|
}
|