X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Fsocket.cpp;h=2a1a71c0a4b3aa404b616f09a7be6e1799660c27;hb=HEAD;hp=67bd38137dbe58eba6d76c51df553d90b4f0d3e3;hpb=3ab65d35cfd696002e09768a38f98e6a2e1ade81;p=libs%2Fnet.git diff --git a/source/net/socket.cpp b/source/net/socket.cpp index 67bd381..2a1a71c 100644 --- a/source/net/socket.cpp +++ b/source/net/socket.cpp @@ -1,8 +1,8 @@ #include "platform_api.h" +#include "socket.h" #include #include #include "sockaddr_private.h" -#include "socket.h" #include "socket_private.h" using namespace std; @@ -11,7 +11,7 @@ namespace Msp { namespace Net { Socket::Socket(const Private &p): - priv(new Private) + priv(make_unique()) { mode = IO::M_RDWR; @@ -19,18 +19,23 @@ Socket::Socket(const Private &p): SockAddr::SysAddr sa; getsockname(priv->handle, reinterpret_cast(&sa.addr), &sa.size); - local_addr = SockAddr::new_from_sys(sa); + local_addr.reset(SockAddr::new_from_sys(sa)); platform_init(); } Socket::Socket(Family af, int type, int proto): - priv(new Private) + priv(make_unique()) { mode = IO::M_RDWR; - // TODO use SOCK_CLOEXEC on Linux +#ifdef __linux__ + type |= SOCK_CLOEXEC; +#endif priv->handle = socket(family_to_sys(af), type, proto); +#ifndef __linux__ + set_inherit(false); +#endif platform_init(); } @@ -38,9 +43,6 @@ Socket::Socket(Family af, int type, int proto): Socket::~Socket() { platform_cleanup(); - - delete local_addr; - delete priv; } void Socket::set_block(bool b) @@ -74,8 +76,7 @@ void Socket::bind(const SockAddr &addr) if(err==-1) throw system_error("bind"); - delete local_addr; - local_addr = addr.copy(); + local_addr.reset(addr.copy()); } const SockAddr &Socket::get_local_address() const