posix/socket: add wrappers for connect and bind
This commit is contained in:
parent
d2b36ebded
commit
f0eb3f0775
@ -136,6 +136,30 @@ socket::operator= (socket &&rhs) noexcept
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
socket::bind (sockaddr_in const &addr)
|
||||
{
|
||||
util::posix::error::try_code (
|
||||
::bind (
|
||||
native (),
|
||||
reinterpret_cast<sockaddr const*> (&addr),
|
||||
sizeof (addr)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
socket::connect (sockaddr_in const &addr)
|
||||
{
|
||||
util::posix::error::try_code (
|
||||
::connect (native (), reinterpret_cast<sockaddr const*>(&addr), sizeof (addr))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
socket::connect (util::view<const char*> host, int port)
|
||||
{
|
||||
const lookup l { host, port };
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
struct sockaddr_in;
|
||||
|
||||
namespace util::posix {
|
||||
class socket : public fd {
|
||||
public:
|
||||
@ -46,6 +48,9 @@ namespace util::posix {
|
||||
// because windows...
|
||||
~socket ();
|
||||
|
||||
void bind (::sockaddr_in const&);
|
||||
|
||||
void connect (::sockaddr_in const&);
|
||||
void connect (util::view<const char*> host, int port);
|
||||
void shutdown ();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user