]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/socket.cpp
Use nullptr instead of 0 for pointers
[libs/net.git] / source / net / socket.cpp
index e8e5eaf6275eddb27634a0d473377bed18570d8b..67bd38137dbe58eba6d76c51df553d90b4f0d3e3 100644 (file)
@@ -5,12 +5,13 @@
 #include "socket.h"
 #include "socket_private.h"
 
+using namespace std;
+
 namespace Msp {
 namespace Net {
 
 Socket::Socket(const Private &p):
-       priv(new Private),
-       local_addr(0)
+       priv(new Private)
 {
        mode = IO::M_RDWR;
 
@@ -24,11 +25,11 @@ Socket::Socket(const Private &p):
 }
 
 Socket::Socket(Family af, int type, int proto):
-       priv(new Private),
-       local_addr(0)
+       priv(new Private)
 {
        mode = IO::M_RDWR;
 
+       // TODO use SOCK_CLOEXEC on Linux
        priv->handle = socket(family_to_sys(af), type, proto);
 
        platform_init();
@@ -44,13 +45,22 @@ Socket::~Socket()
 
 void Socket::set_block(bool b)
 {
-       mode = (mode&~IO::M_NONBLOCK);
-       if(b)
-               mode = (mode|IO::M_NONBLOCK);
-
+       IO::adjust_mode(mode, IO::M_NONBLOCK, !b);
        priv->set_block(b);
 }
 
+void Socket::set_inherit(bool i)
+{
+       IO::adjust_mode(mode, IO::M_INHERIT, i);
+       priv->set_inherit(i);
+}
+
+const IO::Handle &Socket::get_handle(IO::Mode)
+{
+       // TODO could this be implemented somehow?
+       throw unsupported("Socket::get_handle");
+}
+
 const IO::Handle &Socket::get_event_handle()
 {
        return priv->event;
@@ -70,7 +80,7 @@ void Socket::bind(const SockAddr &addr)
 
 const SockAddr &Socket::get_local_address() const
 {
-       if(local_addr==0)
+       if(!local_addr)
                throw bad_socket_state("not bound");
        return *local_addr;
 }