0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-02 13:48:53 +02:00

ircd: Feed received tape into the machine.

This commit is contained in:
Jason Volk 2016-09-12 15:10:56 -07:00
parent fe7a1faccb
commit a9f967d16a
4 changed files with 66 additions and 8 deletions

View file

@ -55,11 +55,17 @@ enum class dc
FIN_RECV, // graceful shutdown recv side
};
bool connected(const client &) noexcept;
bool disconnect(std::nothrow_t, client &, const dc & = dc::FIN) noexcept;
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::unique_ptr<struct sock>);

View file

@ -59,6 +59,7 @@ cmd &find(const std::string &name);
void execute(client &client, 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, tape &);
} // namespace cmds

View file

@ -124,9 +124,11 @@ namespace ircd
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 set_recv(client &);
}
using namespace ircd;
@ -243,11 +245,7 @@ try
auto &rbuf(client.rbuf);
auto &reel(rbuf.reel);
for(const auto &line : reel)
std::cout << line << std::endl;
reel.clear();
set_recv(client);
execute(client, reel);
}
catch(const rfc1459::syntax_error &e)
{
@ -273,6 +271,45 @@ ircd::handle_error(client &client,
case success: return true;
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

View file

@ -65,6 +65,17 @@ ircd::cmds::cmd::emplace()
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
ircd::cmds::execute(client &client,
const uint8_t *const &ptr,
@ -84,6 +95,9 @@ void
ircd::cmds::execute(client &client,
line line)
{
if(line.empty())
return;
auto &handle(find(command(line)));
handle(client, std::move(line));
}