Fix bug in mingw driver, work on lpxclient
This commit is contained in:
@@ -169,6 +169,7 @@ public:
|
||||
} else {
|
||||
socket_[chid] = sock;
|
||||
connected_[chid] = false;
|
||||
Sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,6 +237,7 @@ public:
|
||||
bool any = false;
|
||||
for (const auto &p : listen_sockets_) {
|
||||
FD_SET(p.second, &rfds);
|
||||
FD_SET(p.second, &efds);
|
||||
any = true;
|
||||
}
|
||||
for (int chid = 1; chid < MAX_CHAN; chid++) {
|
||||
@@ -243,7 +245,8 @@ public:
|
||||
if (sock == INVALID_SOCKET) continue;
|
||||
any = true;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -291,7 +294,7 @@ public:
|
||||
assert(status != SOCKET_ERROR);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
if ((nrecv == SOCKET_ERROR) || (nrecv == 0)) {
|
||||
close_socket(chid, "recv failure");
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#include "world.hpp"
|
||||
#include "luaconsole.hpp"
|
||||
#include "invocation.hpp"
|
||||
#include "util.hpp"
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
class LpxClient : public DrivenEngine {
|
||||
public:
|
||||
@@ -17,13 +19,6 @@ public:
|
||||
Gui gui_;
|
||||
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:
|
||||
virtual void event_init(int argc, char *argv[]) {
|
||||
// Create the world model.
|
||||
@@ -40,7 +35,52 @@ public:
|
||||
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() {
|
||||
// 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.
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user