0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd: Replace the client write_closure thing.

This commit is contained in:
Jason Volk 2018-03-11 10:48:58 -07:00
parent bbc1844c61
commit f11be8a0d8
3 changed files with 20 additions and 42 deletions

View file

@ -16,9 +16,7 @@ namespace ircd
struct client;
//TODO: want to upgrade
const char *write(client &, const char *&start, const char *const &stop);
char *read(client &, char *&start, char *const &stop);
http::response::write_closure write_closure(client &);
parse::read_closure read_closure(client &);
void close_all_clients();
@ -54,6 +52,7 @@ struct ircd::client
resource::request request;
bool longpoll {false};
size_t write_all(const const_buffer &);
void close(const net::close_opts &, net::close_callback);
ctx::future<void> close(const net::close_opts & = {});

View file

@ -88,22 +88,6 @@ noexcept
// util
//
ircd::http::response::write_closure
ircd::write_closure(client &client)
{
// returns a function that can be called to send an iovector of data to a client
return [&client](const ilist<const const_buffer> &iov)
{
//std::cout << "<<<< " << size(iov) << std::endl;
//std::cout << iov << std::endl;
//std::cout << "---- " << std::endl;
const auto written
{
write(*client.sock, iov)
};
};
}
ircd::parse::read_closure
ircd::read_closure(client &client)
{
@ -135,23 +119,6 @@ ircd::read(client &client,
return base;
}
const char *
ircd::write(client &client,
const char *&start,
const char *const &stop)
{
assert(client.sock);
auto &sock(*client.sock);
const const_buffer buf
{
start, stop
};
const char *const base(start);
start += net::write(sock, buf);
return base;
}
std::shared_ptr<ircd::client>
ircd::add_client(std::shared_ptr<socket> s)
{
@ -763,3 +730,15 @@ ircd::client::close(const net::close_opts &opts,
{
net::close(*sock, opts, std::move(callback));
}
size_t
ircd::client::write_all(const const_buffer &buf)
{
if(unlikely(!sock))
throw error
{
"No socket to client."
};
return net::write_all(*sock, buf);
}

View file

@ -645,12 +645,12 @@ ircd::resource::response::response(client &client,
};
// All content gets sent
const ilist<const const_buffer> vector
const size_t written
{
content
client.write_all(content)
};
write_closure(client)(vector);
assert(written == size(content));
}
ircd::resource::response::response(client &client,
@ -696,13 +696,11 @@ ircd::resource::response::response(client &client,
"HTTP headers too large for buffer of %zu", sizeof(head_buf)
};
const ilist<const const_buffer> vector
const size_t written
{
head.completed()
client.write_all(head.completed())
};
write_closure(client)(vector);
log::debug
{
"socket(%p) local[%s] remote[%s] HTTP %d %s in %ld$us; %s %zu content",
@ -715,4 +713,6 @@ ircd::resource::response::response(client &client,
content_type,
content_length,
};
assert(written == size(head.completed()));
}