]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/socket.cpp
Include the matching header first in .cpp files
[libs/net.git] / source / net / socket.cpp
index 85cc9872a0df0a802555e80e63df446a8f568fc8..84db6375c5c7b96c0db0a211e6ff201f527a0c49 100644 (file)
@@ -1,8 +1,8 @@
 #include "platform_api.h"
+#include "socket.h"
 #include <msp/core/systemerror.h>
 #include <msp/io/handle_private.h>
 #include "sockaddr_private.h"
-#include "socket.h"
 #include "socket_private.h"
 
 using namespace std;
@@ -11,8 +11,7 @@ namespace Msp {
 namespace Net {
 
 Socket::Socket(const Private &p):
-       priv(new Private),
-       local_addr(0)
+       priv(make_unique<Private>())
 {
        mode = IO::M_RDWR;
 
@@ -20,14 +19,13 @@ Socket::Socket(const Private &p):
 
        SockAddr::SysAddr sa;
        getsockname(priv->handle, reinterpret_cast<sockaddr *>(&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),
-       local_addr(0)
+       priv(make_unique<Private>())
 {
        mode = IO::M_RDWR;
 
@@ -40,9 +38,6 @@ Socket::Socket(Family af, int type, int proto):
 Socket::~Socket()
 {
        platform_cleanup();
-
-       delete local_addr;
-       delete priv;
 }
 
 void Socket::set_block(bool b)
@@ -60,7 +55,7 @@ void Socket::set_inherit(bool i)
 const IO::Handle &Socket::get_handle(IO::Mode)
 {
        // TODO could this be implemented somehow?
-       throw logic_error("Socket::get_handle");
+       throw unsupported("Socket::get_handle");
 }
 
 const IO::Handle &Socket::get_event_handle()
@@ -76,13 +71,12 @@ 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
 {
-       if(local_addr==0)
+       if(!local_addr)
                throw bad_socket_state("not bound");
        return *local_addr;
 }