diff --git a/include/fc/filesystem.hpp b/include/fc/filesystem.hpp index 1c3d131..5cea39e 100644 --- a/include/fc/filesystem.hpp +++ b/include/fc/filesystem.hpp @@ -108,6 +108,7 @@ namespace fc { uint64_t file_size( const path& p ); bool remove( const path& p ); void copy( const path& from, const path& to ); + void rename( const path& from, const path& to ); void create_hard_link( const path& from, const path& to ); path unique_path(); diff --git a/include/fc/udp_socket.hpp b/include/fc/udp_socket.hpp index d7b5a25..e5f0d5e 100644 --- a/include/fc/udp_socket.hpp +++ b/include/fc/udp_socket.hpp @@ -1,11 +1,11 @@ -#ifndef _FC_UDP_SOCKET_HPP_ -#define _FC_UDP_SOCKET_HPP_ +#pragma once #include #include namespace fc { namespace ip { class endpoint; + class address; } /** @@ -25,6 +25,10 @@ namespace fc { size_t send_to( const char* b, size_t l, const fc::ip::endpoint& to ); void close(); + void set_multicast_enable_loopback( bool ); + void set_reuse_address( bool ); + void join_multicast_group( const fc::ip::address& a ); + void connect( const fc::ip::endpoint& e ); fc::ip::endpoint local_endpoint()const; @@ -34,5 +38,3 @@ namespace fc { }; } - -#endif diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 40993b9..6980572 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -147,6 +147,17 @@ namespace fc { bool is_regular_file( const path& p ) { return boost::filesystem::is_regular_file(p); } uint64_t file_size( const path& p ) { return boost::filesystem::file_size(p); } void remove_all( const path& p ) { boost::filesystem::remove_all(p); } + void rename( const path& f, const path& t ) { + try { + boost::filesystem::rename( boost::filesystem::path(f), boost::filesystem::path(t) ); + } catch ( boost::system::system_error& e ) { + FC_THROW_REPORT( "Rename from ${srcfile} to ${dstfile} failed because ${reason}", + fc::value().set("srcfile",f).set("dstfile",t).set("reason",e.what() ) ); + } catch ( ... ) { + FC_THROW_REPORT( "Rename from ${srcfile} to ${dstfile} failed", + fc::value().set("srcfile",f).set("dstfile",t).set("inner", fc::except_str() ) ); + } + } void copy( const path& f, const path& t ) { try { boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t) ); diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index 814f5f2..334570e 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -91,4 +91,17 @@ namespace fc { my->_sock.connect( to_asio_ep(e) ); } + void udp_socket::set_multicast_enable_loopback( bool s ) + { + my->_sock.set_option( boost::asio::ip::multicast::enable_loopback(s) ); + } + void udp_socket::set_reuse_address( bool s ) + { + my->_sock.set_option( boost::asio::ip::udp::socket::reuse_address(s) ); + } + void udp_socket::join_multicast_group( const fc::ip::address& a ) + { + my->_sock.set_option( boost::asio::ip::multicast::join_group( boost::asio::ip::address_v4(a) ) ); + } + }