socket: correctly iterate over lookup entries
This commit is contained in:
parent
39894b5619
commit
a979b253f5
@ -62,7 +62,7 @@ public:
|
|||||||
auto end (void) const { return nullptr; }
|
auto end (void) const { return nullptr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<addrinfo[],void(*)(addrinfo*)> m_addresses;
|
std::unique_ptr<addrinfo,void(*)(addrinfo*)> m_addresses;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -88,6 +88,12 @@ connect_host (const util::view<const char*> host, int port)
|
|||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
socket::socket (int _fd):
|
||||||
|
fd (_fd)
|
||||||
|
{ ; }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
socket::socket (int domain, int type):
|
socket::socket (int domain, int type):
|
||||||
socket (domain, type, 0)
|
socket (domain, type, 0)
|
||||||
{ ; }
|
{ ; }
|
||||||
@ -110,12 +116,28 @@ socket::~socket ()
|
|||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
socket::socket (socket &&rhs):
|
||||||
|
fd (std::move (rhs))
|
||||||
|
{ ; }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
class socket&
|
||||||
|
socket::operator= (socket &&rhs)
|
||||||
|
{
|
||||||
|
fd::operator= (std::move (rhs));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
void
|
void
|
||||||
socket::connect (util::view<const char*> host, int port)
|
socket::connect (util::view<const char*> host, int port)
|
||||||
{
|
{
|
||||||
for (const auto &info: lookup { host, port }) {
|
const lookup l { host, port };
|
||||||
if (!::connect (*this, info.ai_addr, info.ai_addrlen))
|
for (auto cursor = l.begin (); cursor != l.end (); cursor = cursor->ai_next) {
|
||||||
|
if (!::connect (*this, cursor->ai_addr, cursor->ai_addrlen))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,24 +28,31 @@
|
|||||||
namespace util::posix {
|
namespace util::posix {
|
||||||
class socket : public fd {
|
class socket : public fd {
|
||||||
public:
|
public:
|
||||||
|
explicit socket (int _fd);
|
||||||
|
|
||||||
socket (int domain, int type);
|
socket (int domain, int type);
|
||||||
socket (int domain, int type, int protocol);
|
socket (int domain, int type, int protocol);
|
||||||
|
|
||||||
socket (util::view<const char*> host, int port);
|
socket (util::view<const char*> host, int port);
|
||||||
|
|
||||||
void connect (util::view<const char*> host, int port);
|
socket (const socket&) = delete;
|
||||||
|
socket& operator= (const socket&) = delete;
|
||||||
|
|
||||||
|
socket (socket &&rhs);
|
||||||
|
socket& operator= (socket &&);
|
||||||
|
|
||||||
// the destructor is provided so that we can operate more cleanly on
|
// the destructor is provided so that we can operate more cleanly on
|
||||||
// win32 where we must call closesocket instead of the normal close.
|
// win32 where we must call closesocket instead of the normal close.
|
||||||
// because windows...
|
// because windows...
|
||||||
~socket ();
|
~socket ();
|
||||||
|
|
||||||
|
void connect (util::view<const char*> host, int port);
|
||||||
void shutdown ();
|
void shutdown ();
|
||||||
|
|
||||||
template <typename ValueT>
|
template <typename ValueT>
|
||||||
void setoption (int _level, int _name, const ValueT &_value)
|
void setoption (int _level, int _name, const ValueT &_value)
|
||||||
{
|
{
|
||||||
error::try_code (
|
error::try_value (
|
||||||
setsockopt (
|
setsockopt (
|
||||||
native (),
|
native (),
|
||||||
_level,
|
_level,
|
||||||
|
Loading…
Reference in New Issue
Block a user