4 #include "platform_api.h"
5 #include <msp/core/systemerror.h>
6 #include <msp/io/handle_private.h>
7 #include <msp/time/rawtime_private.h>
8 #include "sockaddr_private.h"
10 #include "socket_private.h"
17 void Socket::platform_init()
19 *priv->event = priv->handle;
23 void Socket::platform_cleanup()
28 void Socket::set_timeout(const Time::TimeDelta &timeout)
30 timeval tv = Time::rawtime_to_timeval(timeout.raw());
31 priv->set_option(SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(timeval));
32 priv->set_option(SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(timeval));
35 void Socket::set_platform_events(unsigned)
40 void Socket::Private::set_block(bool b)
42 int flags = fcntl(handle, F_GETFL);
43 fcntl(handle, F_SETFL, (flags&~O_NONBLOCK)|(b?0:O_NONBLOCK));
46 void Socket::Private::set_inherit(bool i)
48 int flags = fcntl(handle, F_GETFD);
49 fcntl(handle, F_SETFD, (flags&~O_CLOEXEC)|(i?0:O_CLOEXEC));
52 int Socket::Private::set_option(int level, int optname, const void *optval, socklen_t optlen)
54 return setsockopt(handle, level, optname, optval, optlen);
57 int Socket::Private::get_option(int level, int optname, void *optval, socklen_t *optlen)
59 return getsockopt(handle, level, optname, optval, optlen);
63 size_t check_sys_error(make_signed<size_t>::type ret, const char *func)
70 throw system_error(func);
76 bool check_sys_connect_error(int ret)
80 if(errno==EINPROGRESS)
83 throw system_error("connect");