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

ircd: sendf() directly to client (prelim).

This commit is contained in:
Jason Volk 2016-09-18 16:25:58 -07:00
parent 5dd280bb3b
commit 581ca84439
2 changed files with 42 additions and 0 deletions

View file

@ -65,6 +65,17 @@ void recv_cancel(client &);
void recv_next(client &, const std::chrono::milliseconds &timeout);
void recv_next(client &);
class sendf
:std::array<char, BUFSIZE>
,public fmt::snprintf
{
void flush(client &);
public:
template<class... Args>
sendf(client &, const char *const &fmt, Args&&... args);
};
// 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 &);
@ -76,6 +87,19 @@ std::shared_ptr<client> add_client(std::shared_ptr<struct sock>);
using clist = std::list<std::shared_ptr<client>>;
const clist &clients();
template<class... Args>
sendf::sendf(client &client,
const char *const &fmt,
Args&&... args)
:fmt::snprintf
{
array::data(), array::size(), fmt, std::forward<Args>(args)...
}
{
flush(client);
}
} // namespace ircd
#endif // __cplusplus

View file

@ -91,6 +91,24 @@ ircd::add_client()
return client;
}
void
ircd::sendf::flush(client &client)
{
static const char *const terminator
{
"\r\n"
};
const std::array<const_buffer, 2> buffers
{{
{ buffer(), std::min(consumed(), size_t(510)) }, //TODO: framemax
{ terminator, 2 }
}};
auto &sock(socket(client));
sock.send(buffers);
}
bool
ircd::disconnect(std::nothrow_t,
client &client,