X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=blobdiff_plain;f=source%2Fnet%2Funix%2Fsocket.cpp;fp=source%2Fnet%2Funix%2Fsocket.cpp;h=02ef7c3c06c4999e7d62ebe838427918271f6d99;hp=0000000000000000000000000000000000000000;hb=88bbb4039aa274c7f41ebe3a18085b63427e5475;hpb=6f6845971a21c2d7e04b87925f5e657f0f20ca0d diff --git a/source/net/unix/socket.cpp b/source/net/unix/socket.cpp new file mode 100644 index 0000000..02ef7c3 --- /dev/null +++ b/source/net/unix/socket.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include "platform_api.h" +#include +#include +#include +#include "sockaddr_private.h" +#include "socket.h" +#include "socket_private.h" + +namespace Msp { +namespace Net { + +void Socket::platform_init() +{ + *priv->event = priv->handle; +} + +void Socket::platform_cleanup() +{ + close(priv->handle); +} + +void Socket::set_timeout(const Time::TimeDelta &timeout) +{ + timeval tv = Time::rawtime_to_timeval(timeout.raw()); + priv->set_option(SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(timeval)); + priv->set_option(SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(timeval)); +} + +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)); +} + +int Socket::Private::set_option(int level, int optname, const void *optval, socklen_t optlen) +{ + return setsockopt(handle, level, optname, optval, optlen); +} + +int Socket::Private::get_option(int level, int optname, void *optval, socklen_t *optlen) +{ + return getsockopt(handle, level, optname, optval, optlen); +} + + +unsigned check_sys_error(int ret, const char *func) +{ + if(ret<0) + { + if(errno==EAGAIN) + return 0; + else + throw system_error(func); + } + + return ret; +} + +bool check_sys_connect_error(int ret) +{ + if(ret<0) + { + if(errno==EINPROGRESS) + return false; + else + throw system_error("connect"); + } + + return true; +} + +} // namespace Net +} // namespace Msp