0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 02:02:38 +01:00

ircd::net: Minor simplify API.

This commit is contained in:
Jason Volk 2018-01-01 17:16:39 -07:00
parent 2bca92d85d
commit 6f81d0c643
2 changed files with 68 additions and 88 deletions

View file

@ -70,20 +70,18 @@ namespace ircd::net
ipport local_ipport(const socket &) noexcept;
ipport remote_ipport(const socket &) noexcept;
const_raw_buffer peer_cert_der(const mutable_raw_buffer &, const socket &);
size_t write(socket &, const ilist<const_buffer> &); // write_all
size_t write(socket &, const iov<const_buffer> &); // write_all
size_t write(socket &, const const_buffer &); // write_all
size_t write(socket &, iov<const_buffer> &); // write_some
size_t read(socket &, const ilist<mutable_buffer> &); // read_all
size_t read(socket &, const iov<mutable_buffer> &); // read_all
size_t read(socket &, const mutable_buffer &); // read_all
size_t read(socket &, iov<mutable_buffer> &); // read_some
std::shared_ptr<socket> connect(const remote &, const milliseconds &timeout = 30000ms);
bool disconnect(socket &, const dc &type = dc::SSL_NOTIFY) noexcept;
const_raw_buffer peer_cert_der(const mutable_raw_buffer &, const socket &);
}
struct ircd::net::init

View file

@ -57,32 +57,6 @@ ircd::net::init::~init()
// socket (public)
//
ircd::const_raw_buffer
ircd::net::peer_cert_der(const mutable_raw_buffer &buf,
const socket &socket)
{
const SSL &ssl(socket);
const X509 &cert(openssl::get_peer_cert(ssl));
return openssl::i2d(buf, cert);
}
std::shared_ptr<ircd::net::socket>
ircd::net::connect(const net::remote &remote,
const milliseconds &timeout)
{
const auto ep{make_endpoint(remote)};
return connect(ep, timeout);
}
std::shared_ptr<ircd::net::socket>
ircd::net::connect(const ip::tcp::endpoint &remote,
const milliseconds &timeout)
{
const auto ret(std::make_shared<socket>());
ret->connect(remote, timeout);
return ret;
}
bool
ircd::net::disconnect(socket &socket,
const dc &type)
@ -102,6 +76,23 @@ catch(const std::exception &e)
return false;
}
std::shared_ptr<ircd::net::socket>
ircd::net::connect(const net::remote &remote,
const milliseconds &timeout)
{
const auto ep{make_endpoint(remote)};
return connect(ep, timeout);
}
std::shared_ptr<ircd::net::socket>
ircd::net::connect(const ip::tcp::endpoint &remote,
const milliseconds &timeout)
{
const auto ret(std::make_shared<socket>());
ret->connect(remote, timeout);
return ret;
}
size_t
ircd::net::read(socket &socket,
iov<mutable_buffer> &bufs)
@ -119,14 +110,6 @@ ircd::net::read(socket &socket,
return socket.read(bufs);
}
size_t
ircd::net::read(socket &socket,
const mutable_buffer &buf)
{
const ilist<mutable_buffer> bufs{buf};
return socket.read(bufs);
}
size_t
ircd::net::write(socket &socket,
iov<const_buffer> &bufs)
@ -146,16 +129,6 @@ ircd::net::write(socket &socket,
return wrote;
}
size_t
ircd::net::write(socket &socket,
const const_buffer &buf)
{
const ilist<const_buffer> bufs{buf};
const size_t wrote(socket.write(bufs));
assert(wrote == size(bufs));
return wrote;
}
size_t
ircd::net::write(socket &socket,
const ilist<const_buffer> &bufs)
@ -165,6 +138,55 @@ ircd::net::write(socket &socket,
return wrote;
}
ircd::const_raw_buffer
ircd::net::peer_cert_der(const mutable_raw_buffer &buf,
const socket &socket)
{
const SSL &ssl(socket);
const X509 &cert(openssl::get_peer_cert(ssl));
return openssl::i2d(buf, cert);
}
ircd::net::ipport
ircd::net::local_ipport(const socket &socket)
noexcept try
{
const auto &ep(socket.local());
return make_ipport(ep);
}
catch(...)
{
return {};
}
ircd::net::ipport
ircd::net::remote_ipport(const socket &socket)
noexcept try
{
const auto &ep(socket.remote());
return make_ipport(ep);
}
catch(...)
{
return {};
}
size_t
ircd::net::available(const socket &s)
noexcept
{
boost::system::error_code ec;
const ip::tcp::socket &sd(s);
return sd.available(ec);
}
bool
ircd::net::connected(const socket &s)
noexcept
{
return s.connected();
}
///////////////////////////////////////////////////////////////////////////////
//
// net/listener.h
@ -670,46 +692,6 @@ ircd::net::sslv23_client
boost::asio::ssl::context::method::sslv23_client
};
ircd::net::ipport
ircd::net::local_ipport(const socket &socket)
noexcept try
{
const auto &ep(socket.local());
return make_ipport(ep);
}
catch(...)
{
return {};
}
ircd::net::ipport
ircd::net::remote_ipport(const socket &socket)
noexcept try
{
const auto &ep(socket.remote());
return make_ipport(ep);
}
catch(...)
{
return {};
}
size_t
ircd::net::available(const socket &s)
noexcept
{
boost::system::error_code ec;
const ip::tcp::socket &sd(s);
return sd.available(ec);
}
bool
ircd::net::connected(const socket &s)
noexcept
{
return s.connected();
}
//
// socket::io
//