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;
20 void Socket::platform_cleanup()
25 void Socket::set_timeout(const Time::TimeDelta &timeout)
27 timeval tv = Time::rawtime_to_timeval(timeout.raw());
28 priv->set_option(SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(timeval));
29 priv->set_option(SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(timeval));
32 void Socket::set_platform_events(unsigned)
37 void Socket::Private::set_block(bool b)
39 int flags = fcntl(handle, F_GETFL);
40 fcntl(handle, F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
43 int Socket::Private::set_option(int level, int optname, const void *optval, socklen_t optlen)
45 return setsockopt(handle, level, optname, optval, optlen);
48 int Socket::Private::get_option(int level, int optname, void *optval, socklen_t *optlen)
50 return getsockopt(handle, level, optname, optval, optlen);
54 unsigned check_sys_error(int ret, const char *func)
61 throw system_error(func);
67 bool check_sys_connect_error(int ret)
71 if(errno==EINPROGRESS)
74 throw system_error("connect");