Outgoing connections now work in mingw driver.

This commit is contained in:
2021-10-08 16:38:10 -04:00
parent e7f55a2411
commit 760bd22874
6 changed files with 98 additions and 24 deletions

View File

@@ -1,9 +1,36 @@
#include "textgame.hpp"
#include "driver.hpp"
#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();
}
}
}
};
int main(int argc, char **argv)
{
TextGame tg;
//TextGame tg;
TNTest tg;
driver_drive(&tg);
}