X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Fsocket.cpp;h=67bd38137dbe58eba6d76c51df553d90b4f0d3e3;hb=3ab65d35cfd696002e09768a38f98e6a2e1ade81;hp=e8e5eaf6275eddb27634a0d473377bed18570d8b;hpb=88bbb4039aa274c7f41ebe3a18085b63427e5475;p=libs%2Fnet.git diff --git a/source/net/socket.cpp b/source/net/socket.cpp index e8e5eaf..67bd381 100644 --- a/source/net/socket.cpp +++ b/source/net/socket.cpp @@ -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; }