posix/socket: allow binding with sockaddr
This commit is contained in:
parent
54df664071
commit
46ff7299bf
@ -134,15 +134,26 @@ socket::operator= (socket &&rhs) noexcept
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
void
|
void
|
||||||
|
socket::bind (sockaddr const &addr)
|
||||||
|
{
|
||||||
|
auto const size = addr.sa_family == AF_INET ? sizeof (sockaddr_in )
|
||||||
|
: addr.sa_family == AF_INET6 ? sizeof (sockaddr_in6)
|
||||||
|
: throw std::runtime_error ("Unhandled sockaddr type");
|
||||||
|
|
||||||
|
cruft::posix::error::try_call (
|
||||||
|
::bind,
|
||||||
|
native (),
|
||||||
|
&addr,
|
||||||
|
size
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void
|
||||||
socket::bind (sockaddr_in const &addr)
|
socket::bind (sockaddr_in const &addr)
|
||||||
{
|
{
|
||||||
cruft::posix::error::try_code (
|
return bind (reinterpret_cast<sockaddr const&> (addr));
|
||||||
::bind (
|
|
||||||
native (),
|
|
||||||
reinterpret_cast<sockaddr const*> (&addr),
|
|
||||||
sizeof (addr)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ namespace cruft::posix {
|
|||||||
// because windows...
|
// because windows...
|
||||||
~socket ();
|
~socket ();
|
||||||
|
|
||||||
|
void bind (::sockaddr const&);
|
||||||
void bind (::sockaddr_in const&);
|
void bind (::sockaddr_in const&);
|
||||||
|
|
||||||
void connect (::sockaddr_in const&);
|
void connect (::sockaddr_in const&);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user