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"
15 void Socket::platform_init()
17 *priv->event = priv->handle;
21 void Socket::platform_cleanup()
26 void Socket::set_timeout(const Time::TimeDelta &timeout)
28 timeval tv = Time::rawtime_to_timeval(timeout.raw());
29 priv->set_option(SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(timeval));
30 priv->set_option(SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(timeval));
33 void Socket::set_platform_events(unsigned)
38 void Socket::Private::set_block(bool b)
40 int flags = fcntl(handle, F_GETFL);
41 fcntl(handle, F_SETFL, (flags&~O_NONBLOCK)|(b?0:O_NONBLOCK));
44 void Socket::Private::set_inherit(bool i)
46 int flags = fcntl(handle, F_GETFD);
47 fcntl(handle, F_SETFD, (flags&~O_CLOEXEC)|(i?O_CLOEXEC:0));
50 int Socket::Private::set_option(int level, int optname, const void *optval, socklen_t optlen)
52 return setsockopt(handle, level, optname, optval, optlen);
55 int Socket::Private::get_option(int level, int optname, void *optval, socklen_t *optlen)
57 return getsockopt(handle, level, optname, optval, optlen);
61 unsigned check_sys_error(int ret, const char *func)
68 throw system_error(func);
74 bool check_sys_connect_error(int ret)
78 if(errno==EINPROGRESS)
81 throw system_error("connect");