peer_addr=0;
}
+void Socket::set_timeout(const Time::TimeDelta &timeout)
+{
+#ifndef WIN32
+ timeval tv;
+ timeout.fill_timeval(tv);
+ set_option(SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(timeval));
+ set_option(SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(timeval));
+#else
+ DWORD msecs = static_cast<DWORD>(timeout/Time::msec);
+ set_option(SOL_SOCKET, SO_RCVTIMEO, &msecs, sizeof(DWORD));
+ set_option(SOL_SOCKET, SO_SNDTIMEO, &msecs, sizeof(DWORD));
+#endif
+}
+
const SockAddr &Socket::get_local_address() const
{
if(local_addr==0)
throw Exception("Socket is not connected");
}
-int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen)
+int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen)
+{
+#ifdef WIN32
+ return setsockopt(handle, level, optname, reinterpret_cast<const char *>(optval), optlen);
+#else
+ return setsockopt(handle, level, optname, optval, optlen);
+#endif
+}
+
+int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen) const
{
#ifdef WIN32
return getsockopt(handle, level, optname, reinterpret_cast<char *>(optval), optlen);