mirror of
https://github.com/matrix-construct/construct
synced 2025-02-19 18:20:19 +01:00
ircd: sendf() directly to client (prelim).
This commit is contained in:
parent
5dd280bb3b
commit
581ca84439
2 changed files with 42 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue