mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 16:04:15 +01:00
ircd: Feed received tape into the machine.
This commit is contained in:
parent
fe7a1faccb
commit
a9f967d16a
4 changed files with 66 additions and 8 deletions
|
@ -55,11 +55,17 @@ enum class dc
|
||||||
FIN_RECV, // graceful shutdown recv side
|
FIN_RECV, // graceful shutdown recv side
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
bool connected(const client &) noexcept;
|
bool connected(const client &) noexcept;
|
||||||
bool disconnect(std::nothrow_t, client &, const dc & = dc::FIN) noexcept;
|
bool disconnect(std::nothrow_t, client &, const dc & = dc::FIN) noexcept;
|
||||||
void disconnect(client &, const dc & = dc::FIN);
|
void disconnect(client &, const dc & = dc::FIN);
|
||||||
|
void set_recv(client &);
|
||||||
|
|
||||||
// Makes a client
|
// Destroys a client. This only removes the client from the clients list,
|
||||||
|
// and may result in a destruction and disconnect, or it may not.
|
||||||
|
void finished(client &);
|
||||||
|
|
||||||
|
// Creates a client.
|
||||||
std::shared_ptr<client> add_client();
|
std::shared_ptr<client> add_client();
|
||||||
std::shared_ptr<client> add_client(std::unique_ptr<struct sock>);
|
std::shared_ptr<client> add_client(std::unique_ptr<struct sock>);
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ cmd &find(const std::string &name);
|
||||||
void execute(client &client, line);
|
void execute(client &client, line);
|
||||||
void execute(client &client, const std::string &line);
|
void execute(client &client, const std::string &line);
|
||||||
void execute(client &client, const uint8_t *const &line, const size_t &len);
|
void execute(client &client, const uint8_t *const &line, const size_t &len);
|
||||||
|
void execute(client &client, tape &);
|
||||||
|
|
||||||
} // namespace cmds
|
} // namespace cmds
|
||||||
|
|
||||||
|
|
|
@ -124,9 +124,11 @@ namespace ircd
|
||||||
|
|
||||||
clist clients_list;
|
clist clients_list;
|
||||||
|
|
||||||
bool handle_error(client &, const error_code &);
|
bool handle_ec_eof(client &);
|
||||||
|
bool handle_ec_cancel(client &);
|
||||||
|
bool handle_ec_success(client &);
|
||||||
|
bool handle_ec(client &, const error_code &);
|
||||||
void handle_recv(client &, const error_code &, const size_t);
|
void handle_recv(client &, const error_code &, const size_t);
|
||||||
void set_recv(client &);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace ircd;
|
using namespace ircd;
|
||||||
|
@ -243,11 +245,7 @@ try
|
||||||
|
|
||||||
auto &rbuf(client.rbuf);
|
auto &rbuf(client.rbuf);
|
||||||
auto &reel(rbuf.reel);
|
auto &reel(rbuf.reel);
|
||||||
for(const auto &line : reel)
|
execute(client, reel);
|
||||||
std::cout << line << std::endl;
|
|
||||||
|
|
||||||
reel.clear();
|
|
||||||
set_recv(client);
|
|
||||||
}
|
}
|
||||||
catch(const rfc1459::syntax_error &e)
|
catch(const rfc1459::syntax_error &e)
|
||||||
{
|
{
|
||||||
|
@ -273,6 +271,45 @@ ircd::handle_error(client &client,
|
||||||
case success: return true;
|
case success: return true;
|
||||||
default: throw boost::system::system_error(ec);
|
default: throw boost::system::system_error(ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::handle_ec_cancel(client &client)
|
||||||
|
{
|
||||||
|
auto &sock(*client.sock);
|
||||||
|
|
||||||
|
// The cancel can come from a timeout or directly.
|
||||||
|
// If directly, the timer may still needs to be canceled
|
||||||
|
if(!sock.timedout)
|
||||||
|
{
|
||||||
|
error_code ec;
|
||||||
|
sock.timer.cancel(ec);
|
||||||
|
assert(ec == boost::system::errc::success);
|
||||||
|
log::debug("client[%s]: recv canceled", string(remote_address(client)).c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
log::debug("client[%s]: recv timeout", string(remote_address(client)).c_str());
|
||||||
|
finished(client);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::handle_ec_eof(client &client)
|
||||||
|
{
|
||||||
|
log::debug("client[%s]: eof", string(remote_address(client)).c_str());
|
||||||
|
finished(client);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ircd::finished(client &client)
|
||||||
|
{
|
||||||
|
const auto p(shared_from(client));
|
||||||
|
clients_list.erase(client.clit);
|
||||||
|
log::debug("client[%p] finished. (refs: %zu)", (const void *)p.get(), p.use_count());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
|
|
14
ircd/cmds.cc
14
ircd/cmds.cc
|
@ -65,6 +65,17 @@ ircd::cmds::cmd::emplace()
|
||||||
log::info("Registered command \"%s\" to handler @ %p", name.c_str(), this);
|
log::info("Registered command \"%s\" to handler @ %p", name.c_str(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ircd::cmds::execute(client &client,
|
||||||
|
tape &reel)
|
||||||
|
{
|
||||||
|
while(!reel.empty())
|
||||||
|
{
|
||||||
|
execute(client, std::move(reel.front()));
|
||||||
|
reel.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::cmds::execute(client &client,
|
ircd::cmds::execute(client &client,
|
||||||
const uint8_t *const &ptr,
|
const uint8_t *const &ptr,
|
||||||
|
@ -84,6 +95,9 @@ void
|
||||||
ircd::cmds::execute(client &client,
|
ircd::cmds::execute(client &client,
|
||||||
line line)
|
line line)
|
||||||
{
|
{
|
||||||
|
if(line.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
auto &handle(find(command(line)));
|
auto &handle(find(command(line)));
|
||||||
handle(client, std::move(line));
|
handle(client, std::move(line));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue