From f11be8a0d8a2bedf1b6d0c25de82eb8f2cd8cc26 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 11 Mar 2018 10:48:58 -0700 Subject: [PATCH] ircd: Replace the client write_closure thing. --- include/ircd/client.h | 3 +-- ircd/client.cc | 45 ++++++++++++------------------------------- ircd/resource.cc | 14 +++++++------- 3 files changed, 20 insertions(+), 42 deletions(-) diff --git a/include/ircd/client.h b/include/ircd/client.h index c31baf480..09693590b 100644 --- a/include/ircd/client.h +++ b/include/ircd/client.h @@ -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 close(const net::close_opts & = {}); diff --git a/ircd/client.cc b/ircd/client.cc index 64cc4a6bc..4b7b61cc9 100644 --- a/ircd/client.cc +++ b/ircd/client.cc @@ -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 &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::add_client(std::shared_ptr 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); +} diff --git a/ircd/resource.cc b/ircd/resource.cc index a898b61ce..131f571b5 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -645,12 +645,12 @@ ircd::resource::response::response(client &client, }; // All content gets sent - const ilist 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 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())); }