Fix bug in mingw driver, work on lpxclient

This commit is contained in:
2021-11-03 11:11:31 -04:00
parent 9a02f408b0
commit 17a1155906
2 changed files with 53 additions and 10 deletions

View File

@@ -169,6 +169,7 @@ public:
} else { } else {
socket_[chid] = sock; socket_[chid] = sock;
connected_[chid] = false; connected_[chid] = false;
Sleep(1000);
} }
} }
} }
@@ -236,6 +237,7 @@ public:
bool any = false; bool any = false;
for (const auto &p : listen_sockets_) { for (const auto &p : listen_sockets_) {
FD_SET(p.second, &rfds); FD_SET(p.second, &rfds);
FD_SET(p.second, &efds);
any = true; any = true;
} }
for (int chid = 1; chid < MAX_CHAN; chid++) { for (int chid = 1; chid < MAX_CHAN; chid++) {
@@ -243,7 +245,8 @@ public:
if (sock == INVALID_SOCKET) continue; if (sock == INVALID_SOCKET) continue;
any = true; any = true;
FD_SET(sock, &rfds); FD_SET(sock, &rfds);
if ((!connected_[chid]) || (!driven_->drv_outgoing_empty(chid))) { FD_SET(sock, &efds);
if (!driven_->drv_outgoing_empty(chid)) {
FD_SET(sock, &wfds); FD_SET(sock, &wfds);
} }
} }
@@ -291,7 +294,7 @@ public:
assert(status != SOCKET_ERROR); assert(status != SOCKET_ERROR);
for (auto &p : listen_sockets_) { for (auto &p : listen_sockets_) {
if (FD_ISSET(p.second, &rfds)) { if (FD_ISSET(p.second, &rfds) || FD_ISSET(p.second, &efds)) {
accept_connections(p.first, p.second); accept_connections(p.first, p.second);
} }
} }
@@ -312,7 +315,7 @@ public:
} }
} }
} }
if (FD_ISSET(sock, &rfds)) { if (FD_ISSET(sock, &rfds) || FD_ISSET(sock, &efds)) {
int nrecv = recv(sock, chbuf.get(), 65536, 0); int nrecv = recv(sock, chbuf.get(), 65536, 0);
if ((nrecv == SOCKET_ERROR) || (nrecv == 0)) { if ((nrecv == SOCKET_ERROR) || (nrecv == 0)) {
close_socket(chid, "recv failure"); close_socket(chid, "recv failure");

View File

@@ -4,7 +4,9 @@
#include "world.hpp" #include "world.hpp"
#include "luaconsole.hpp" #include "luaconsole.hpp"
#include "invocation.hpp" #include "invocation.hpp"
#include "util.hpp"
#include <memory> #include <memory>
#include <iostream>
class LpxClient : public DrivenEngine { class LpxClient : public DrivenEngine {
public: public:
@@ -17,13 +19,6 @@ public:
Gui gui_; Gui gui_;
int64_t gui_place_; int64_t gui_place_;
void do_view_command(const StringVec &cmd);
void do_menu_command(const StringVec &cmd);
void do_choose_command(const StringVec &cmd);
void do_quit_command(const StringVec &cmd);
void do_lua(const std::string &exp);
void do_command(const StringVec &exp);
public: public:
virtual void event_init(int argc, char *argv[]) { virtual void event_init(int argc, char *argv[]) {
// Create the world model. // Create the world model.
@@ -40,7 +35,52 @@ public:
channel_ = new_outgoing_channel("localhost:8085"); channel_ = new_outgoing_channel("localhost:8085");
} }
void do_lua(const std::string &lua) {
std::cerr << "Lua: " << lua << std::endl;
}
void do_command(const util::StringVec &words) {
std::cerr << "Command: ";
for (const std::string &word : words) {
std::cerr << word << " ";
}
std::cerr << std::endl;
}
void console_process(const std::string &line) {
console_.add(line);
int action = console_.action();
if (action == LuaConsole::DO_LUA) {
do_lua(console_.lua_expression());
console_.clear();
} else if (action == LuaConsole::DO_COMMAND) {
do_command(console_.words());
console_.clear();
} else if (action == LuaConsole::DO_SYNTAX) {
std::cerr << console_.syntax() << std::endl;
console_.clear();
}
}
virtual void event_update() { virtual void event_update() {
// Check for keyboard input on stdin.
while (true) {
std::string line = get_stdio_channel()->in()->readline();
if (line == "") break;
console_process(line);
get_stdio_channel()->out()->write_bytes(console_.get_prompt());
}
// Check for communication from server..
if (channel_ != nullptr) {
if (channel_->closed()) {
std::cerr << "Server closed connection " << channel_->error() << std::endl;
channel_.reset();
// stop_driver();
} else {
// Implement reception of messages.
}
}
} }
}; };