X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Funix%2Fsocket.cpp;h=2c1e2ad8d355ac9e0fe9a31b5292f0709535c2f8;hb=HEAD;hp=02ef7c3c06c4999e7d62ebe838427918271f6d99;hpb=88bbb4039aa274c7f41ebe3a18085b63427e5475;p=libs%2Fnet.git diff --git a/source/net/unix/socket.cpp b/source/net/unix/socket.cpp index 02ef7c3..2c1e2ad 100644 --- a/source/net/unix/socket.cpp +++ b/source/net/unix/socket.cpp @@ -1,20 +1,23 @@ +#include "platform_api.h" +#include "socket.h" #include #include #include -#include "platform_api.h" #include #include #include #include "sockaddr_private.h" -#include "socket.h" #include "socket_private.h" +using namespace std; + namespace Msp { namespace Net { void Socket::platform_init() { *priv->event = priv->handle; + set_inherit(false); } void Socket::platform_cleanup() @@ -37,7 +40,13 @@ void Socket::set_platform_events(unsigned) void Socket::Private::set_block(bool b) { int flags = fcntl(handle, F_GETFL); - fcntl(handle, F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK)); + fcntl(handle, F_SETFL, (flags&~O_NONBLOCK)|(b?0:O_NONBLOCK)); +} + +void Socket::Private::set_inherit(bool i) +{ + int flags = fcntl(handle, F_GETFD); + fcntl(handle, F_SETFD, (flags&~O_CLOEXEC)|(i?0:O_CLOEXEC)); } int Socket::Private::set_option(int level, int optname, const void *optval, socklen_t optlen) @@ -51,11 +60,11 @@ int Socket::Private::get_option(int level, int optname, void *optval, socklen_t } -unsigned check_sys_error(int ret, const char *func) +size_t check_sys_error(make_signed::type ret, const char *func) { if(ret<0) { - if(errno==EAGAIN) + if(errno==EAGAIN || errno==EWOULDBLOCK) return 0; else throw system_error(func);