Merge branch 'phoenix' of https://github.com/InvictusInnovations/fc into phoenix
This commit is contained in:
commit
32b7b02b15
8 changed files with 137 additions and 15 deletions
|
|
@ -175,7 +175,7 @@ ELSE()
|
|||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall" )
|
||||
|
||||
IF(APPLE)
|
||||
target_compile_options(fc PUBLIC -std=c++11 -stdlib=libc++ -Wall)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libc++ -Wall" )
|
||||
ELSE()
|
||||
target_compile_options(fc PUBLIC -std=c++11 -Wall -fnon-call-exceptions -Wno-unused-local-typedefs -fmax-errors=3)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-local-typedefs -fmax-errors=3 ")
|
||||
|
|
|
|||
|
|
@ -135,8 +135,16 @@ namespace fc {
|
|||
|
||||
void create_hard_link( const path& from, const path& to );
|
||||
|
||||
path unique_path();
|
||||
path temp_directory_path();
|
||||
path unique_path();
|
||||
path temp_directory_path();
|
||||
|
||||
/** @return the home directory on Linux and OS X and the Profile directory on Windows */
|
||||
const path& home_path();
|
||||
|
||||
/** @return the home_path() on Linux, home_path()/Library/Application Support/ on OS X,
|
||||
* and APPDATA on windows
|
||||
*/
|
||||
const path& app_path();
|
||||
|
||||
class variant;
|
||||
void to_variant( const fc::path&, fc::variant& );
|
||||
|
|
|
|||
8
include/fc/io/console.hpp
Normal file
8
include/fc/io/console.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
namespace fc
|
||||
{
|
||||
/** enables / disables echoing of console input, useful for
|
||||
* entering passwords on the console.
|
||||
*/
|
||||
void set_console_echo( bool enable_echo );
|
||||
} // namespace fc
|
||||
|
|
@ -52,9 +52,10 @@ namespace fc {
|
|||
tcp_server();
|
||||
~tcp_server();
|
||||
|
||||
void close();
|
||||
void accept( tcp_socket& s );
|
||||
void listen( uint16_t port );
|
||||
void close();
|
||||
void accept( tcp_socket& s );
|
||||
void listen( uint16_t port );
|
||||
void listen( const fc::ip::endpoint& ep );
|
||||
uint16_t get_port()const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include <boost/signal.hpp>
|
||||
#include <boost/signals2/signal.hpp>
|
||||
#include <fc/thread/future.hpp>
|
||||
#include <fc/thread/thread.hpp>
|
||||
|
||||
|
|
@ -6,20 +6,20 @@
|
|||
namespace fc {
|
||||
#if !defined(BOOST_NO_TEMPLATE_ALIASES)
|
||||
template<typename T>
|
||||
using signal = boost::signal<T>;
|
||||
using signal = boost::signals2::signal<T>;
|
||||
#else
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
inline T wait( boost::signal<void(T)>& sig, const microseconds& timeout_us=microseconds::maximum() ) {
|
||||
inline T wait( boost::signals2::signal<void(T)>& sig, const microseconds& timeout_us=microseconds::maximum() ) {
|
||||
typename promise<T>::ptr p(new promise<T>());
|
||||
boost::signals::scoped_connection c = sig.connect( [=]( T t ) { p->set_value(t); } );
|
||||
boost::signals2::scoped_connection c( sig.connect( [=]( T t ) { p->set_value(t); } ));
|
||||
return p->wait( timeout_us );
|
||||
}
|
||||
|
||||
inline void wait( boost::signal<void()>& sig, const microseconds& timeout_us=microseconds::maximum() ) {
|
||||
inline void wait( boost::signals2::signal<void()>& sig, const microseconds& timeout_us=microseconds::maximum() ) {
|
||||
promise<void>::ptr p(new promise<void>());
|
||||
boost::signals::scoped_connection c = sig.connect( [=]() { p->set_value(); } );
|
||||
boost::signals2::scoped_connection c( sig.connect( [=]() { p->set_value(); } ));
|
||||
p->wait( timeout_us );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <uuid/uuid.h>
|
||||
#endif
|
||||
|
||||
namespace fc {
|
||||
|
|
@ -365,4 +369,51 @@ namespace fc {
|
|||
{
|
||||
_path = fc::optional<fc::path>();
|
||||
}
|
||||
|
||||
const fc::path& home_path()
|
||||
{
|
||||
static fc::path p = []()
|
||||
{
|
||||
#ifdef WIN32
|
||||
char* home = getenv( "USERPROFILE" );
|
||||
if( nullptr == home )
|
||||
{
|
||||
FC_ASSERT( home != nullptr, "The USERPROFILE environment variable is not set" );
|
||||
}
|
||||
return fc::path( home );
|
||||
#else
|
||||
char* home = getenv( "HOME" );
|
||||
if( nullptr == home )
|
||||
{
|
||||
struct passwd* pwd = getpwuid(getuid());
|
||||
if( pwd )
|
||||
{
|
||||
return fc::path( std::string( pwd->pw_dir ) );
|
||||
}
|
||||
FC_ASSERT( home != nullptr, "The HOME environment variable is not set" );
|
||||
}
|
||||
return fc::path( std::string(home) );
|
||||
#endif
|
||||
}();
|
||||
return p;
|
||||
}
|
||||
|
||||
const fc::path& app_path()
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
static fc::path appdir = [](){ return home_path() / "Library" / "Application Support"; }();
|
||||
#elif defined( WIN32 )
|
||||
static fc::path appdir = [](){
|
||||
char* appdata = getenv( "APPDATA" );
|
||||
if( nullptr == appdata )
|
||||
{
|
||||
FC_ASSERT( appdata != nullptr, "The APPDATA environment variable is not set" );
|
||||
}
|
||||
return fc::path( std::string(appdata) );
|
||||
}();
|
||||
#else
|
||||
static fc::path appdir = home_dir();
|
||||
#endif
|
||||
return appdir;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
46
src/io/console.cpp
Normal file
46
src/io/console.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace fc {
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
|
||||
void set_console_echo( bool enable_echo )
|
||||
{
|
||||
auto stdin_handle = GetStdHandle( STD_INPUT_HANDLE );
|
||||
DWORD mode = 0;
|
||||
GetConsoleMode( stdin_handle, &mode );
|
||||
if( enable_echo )
|
||||
{
|
||||
SetConsoleMode( stdin_handle, mode | ENABLE_ECHO_INPUT );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetConsoleMode( stdin_handle, mode & (~ENABLE_ECHO_INPUT) );
|
||||
}
|
||||
}
|
||||
|
||||
#else // NOT WIN32
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void set_console_echo( bool enable_echo )
|
||||
{
|
||||
termios oldt;
|
||||
tcgetattr(STDIN_FILENO, &oldt);
|
||||
termios newt = oldt;
|
||||
if( enable_echo )
|
||||
{
|
||||
newt.c_lflag |= ~ECHO;
|
||||
}
|
||||
else
|
||||
{
|
||||
newt.c_lflag &= ~ECHO;
|
||||
}
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
||||
}
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
} // namespace fc
|
||||
|
|
@ -59,9 +59,12 @@ namespace fc {
|
|||
|
||||
class tcp_server::impl {
|
||||
public:
|
||||
impl(uint16_t port):
|
||||
_accept( fc::asio::default_io_service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port) ){
|
||||
}
|
||||
impl(uint16_t port)
|
||||
:_accept( fc::asio::default_io_service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port) ){}
|
||||
|
||||
impl(const fc::ip::endpoint& ep )
|
||||
:_accept( fc::asio::default_io_service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4( ep.get_address()), ep.port()) ){}
|
||||
|
||||
~impl(){
|
||||
try {
|
||||
_accept.close();
|
||||
|
|
@ -100,6 +103,11 @@ namespace fc {
|
|||
if( my ) delete my;
|
||||
my = new impl(port);
|
||||
}
|
||||
void tcp_server::listen( const fc::ip::endpoint& ep )
|
||||
{
|
||||
if( my ) delete my;
|
||||
my = new impl(ep);
|
||||
}
|
||||
|
||||
uint16_t tcp_server::get_port()const
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue