posix/socket: add wrappers for connect and bind

This commit is contained in:
Danny Robson 2018-07-27 18:29:30 +10:00
parent d2b36ebded
commit f0eb3f0775
2 changed files with 29 additions and 0 deletions

View File

@ -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 };

View File

@ -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 ();