0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-01 19:22:53 +01:00

ircd::net: Unionize datagram for bidirections.

This commit is contained in:
Jason Volk 2018-07-07 22:10:29 -07:00
parent fe0bd19763
commit e5834065ed
2 changed files with 41 additions and 4 deletions

View file

@ -66,10 +66,27 @@ struct ircd::net::listener_udp
struct ircd::net::listener_udp::datagram struct ircd::net::listener_udp::datagram
{ {
mutable_buffer buf; union
{
const_buffer cbuf;
mutable_buffer mbuf;
};
union
{
vector_view<const_buffer> cbufs;
vector_view<mutable_buffer> mbufs;
};
ipport remote; ipport remote;
enum flag flag {(enum flag)0}; enum flag flag {(enum flag)0};
vector_view<mutable_buffer> bufs { &buf, 1 };
datagram(const const_buffer &buf,
const ipport &remote,
const enum flag &flag = (enum flag)0);
datagram(const mutable_buffer &buf,
const enum flag &flag = (enum flag)0);
datagram() = default; datagram() = default;
}; };

View file

@ -1559,11 +1559,11 @@ ircd::net::listener_udp::acceptor::operator()(datagram &datagram)
ip::udp::endpoint ep; ip::udp::endpoint ep;
const size_t rlen const size_t rlen
{ {
a.async_receive_from(datagram.bufs, ep, flags(datagram.flag), yield_context{to_asio{}}) a.async_receive_from(datagram.mbufs, ep, flags(datagram.flag), yield_context{to_asio{}})
}; };
datagram.remote = make_ipport(ep); datagram.remote = make_ipport(ep);
datagram.buf = {data(datagram.buf), rlen}; datagram.mbuf = {data(datagram.mbuf), rlen};
return datagram; return datagram;
} }
@ -1578,6 +1578,26 @@ ircd::net::listener_udp::acceptor::flags(const flag &flag)
return ret; return ret;
} }
//
// listener_udp::datagram
//
ircd::net::listener_udp::datagram::datagram(const const_buffer &buf,
const ipport &remote,
const enum flag &flag)
:cbuf{buf}
,cbufs{&cbuf, 1}
,remote{remote}
,flag{flag}
{}
ircd::net::listener_udp::datagram::datagram(const mutable_buffer &buf,
const enum flag &flag)
:mbuf{buf}
,mbufs{&mbuf, 1}
,flag{flag}
{}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// //
// net/scope_timeout.h // net/scope_timeout.h