void SocketImpl::set_timeout( const milliseconds& value ) { tcp::socket::native_handle_type native_socket(0); #ifdef BUILD_SSL if ( m_socket not_eq nullptr ) { #endif native_socket = m_socket->native_handle( ); #ifdef BUILD_SSL } else { native_socket = m_ssl_socket->lowest_layer( ).native_handle( ); } #endif struct timeval timeout = { 0, 0 }; timeout.tv_usec = static_cast< long >( value.count( ) * 1000 ); int status = setsockopt( native_socket, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast< char* >( &timeout ), sizeof( timeout ) ); if ( status == -1 and m_logger not_eq nullptr ) { m_logger->log( Logger::Level::WARNING, "Failed to set socket option, send timeout." ); } status = setsockopt( native_socket, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast< char* >( &timeout ), sizeof( timeout ) ); if ( status == -1 and m_logger not_eq nullptr ) { m_logger->log( Logger::Level::WARNING, "Failed to set socket option, receive timeout." ); } }
bool select_fd_set::is_set(socket s) { return FD_ISSET(native_socket(s), &SELF.impl) != 0; }
void select_fd_set::set(socket s) { FD_SET(native_socket(s), &SELF.impl); }