various updates
This commit is contained in:
parent
c99759a489
commit
3f73d25e44
12 changed files with 145 additions and 17 deletions
|
|
@ -88,6 +88,7 @@ namespace fc {
|
|||
throw_exception_( func, file, line, msg, to_string(fc::forward<T1>(a1) ), to_string( fc::forward<T2>(a2) ), to_string( fc::forward<T3>(a3) ) );
|
||||
}
|
||||
|
||||
fc::string except_str();
|
||||
|
||||
} // namespace fc
|
||||
#define FC_THROW(X) throw X
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
namespace boost {
|
||||
namespace filesystem {
|
||||
class path;
|
||||
class directory_iterator;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,15 +32,34 @@ namespace fc {
|
|||
operator boost::filesystem::path& ();
|
||||
operator const boost::filesystem::path& ()const;
|
||||
|
||||
fc::path stem()const;
|
||||
fc::path extension()const;
|
||||
fc::path filename()const;
|
||||
fc::path parent_path()const;
|
||||
fc::string string()const;
|
||||
private:
|
||||
fwd<boost::filesystem::path,8> _p;
|
||||
};
|
||||
|
||||
class directory_iterator {
|
||||
public:
|
||||
directory_iterator( const fc::path& p );
|
||||
directory_iterator();
|
||||
~directory_iterator();
|
||||
|
||||
fc::path operator*()const;
|
||||
directory_iterator& operator++(int);
|
||||
directory_iterator& operator++();
|
||||
|
||||
friend bool operator==( const directory_iterator&, const directory_iterator& );
|
||||
friend bool operator!=( const directory_iterator&, const directory_iterator& );
|
||||
private:
|
||||
fwd<boost::filesystem::directory_iterator,8> _p;
|
||||
};
|
||||
|
||||
bool exists( const path& p );
|
||||
bool is_directory( const path& p );
|
||||
bool is_regular( const path& p );
|
||||
bool is_regular_file( const path& p );
|
||||
void create_directories( const path& p );
|
||||
uint64_t file_size( const path& p );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ namespace fc {
|
|||
friend stringstream& operator<<( stringstream&, const bool& );
|
||||
friend stringstream& operator<<( stringstream&, const char& );
|
||||
friend stringstream& operator<<( stringstream&, const fc::string& );
|
||||
friend stringstream& operator<<( stringstream&, const char* );
|
||||
private:
|
||||
class impl;
|
||||
fwd<impl,368> my;
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ namespace fc {
|
|||
|
||||
friend string operator + ( const string&, const string& );
|
||||
friend string operator + ( const string&, char c );
|
||||
|
||||
fc::string substr( int32_t start, int32_t len = 0x7fffffff );
|
||||
|
||||
private:
|
||||
void* my;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ namespace fc {
|
|||
size_t readsome( char* buffer, size_t max );
|
||||
size_t read( char* buffer, size_t s );
|
||||
|
||||
void flush();
|
||||
|
||||
private:
|
||||
friend class tcp_server;
|
||||
class impl;
|
||||
|
|
@ -24,11 +26,11 @@ namespace fc {
|
|||
|
||||
class tcp_server {
|
||||
public:
|
||||
tcp_server();
|
||||
tcp_server(uint16_t port=0);
|
||||
~tcp_server();
|
||||
|
||||
bool accept( tcp_socket& s );
|
||||
void listen( uint16_t port );
|
||||
// void listen( uint16_t port );
|
||||
|
||||
private:
|
||||
class impl;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <fc/asio.hpp>
|
||||
#include <fc/thread.hpp>
|
||||
#include <fc/log.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include <algorithm>
|
||||
#include <string.h>
|
||||
|
||||
#include <fc/log.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/exception.hpp>
|
||||
|
||||
|
|
@ -534,6 +535,7 @@ inline std::string EncodeBase58(const unsigned char* pbegin, const unsigned char
|
|||
|
||||
// Convert little endian std::string to big endian
|
||||
reverse(str.begin(), str.end());
|
||||
// slog( "Encode '%s'", str.c_str() );
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
@ -563,8 +565,10 @@ inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
|
|||
{
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
if (*p != '\0')
|
||||
if (*p != '\0') {
|
||||
slog( "%s '%c'", pszBase58,*p );
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
bnChar.setulong(p1 - pszBase58);
|
||||
|
|
@ -609,6 +613,7 @@ fc::string to_base58( const char* d, uint32_t s ) {
|
|||
* @return the number of bytes decoded
|
||||
*/
|
||||
size_t from_base58( const fc::string& base58_str, char* out_data, size_t out_data_len ) {
|
||||
//slog( "%s", base58_str.c_str() );
|
||||
std::vector<unsigned char> out;
|
||||
if( !DecodeBase58( base58_str.c_str(), out ) ) {
|
||||
FC_THROW_MSG( "Unable to decode base58 string '%s'", base58_str );
|
||||
|
|
|
|||
|
|
@ -102,5 +102,7 @@ namespace fc {
|
|||
const fc::string& a1, const fc::string& a2, const fc::string& a3, const fc::string& a4 ) {
|
||||
::boost::exception_detail::throw_exception_(fc::generic_exception(msg),func, file, line );
|
||||
}
|
||||
fc::string except_str() { return fc::current_exception().diagnostic_information(); }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,11 +56,20 @@ namespace fc {
|
|||
fc::path path::filename()const {
|
||||
return _p->filename();
|
||||
}
|
||||
fc::path path::extension()const {
|
||||
return _p->extension();
|
||||
}
|
||||
fc::path path::stem()const {
|
||||
return _p->stem();
|
||||
}
|
||||
fc::path path::parent_path()const {
|
||||
return _p->parent_path();
|
||||
}
|
||||
|
||||
|
||||
bool exists( const path& p ) { return boost::filesystem::exists(p); }
|
||||
void create_directories( const path& p ) { boost::filesystem::create_directories(p); }
|
||||
bool is_directory( const path& p ) { return boost::filesystem::is_directory(p); }
|
||||
bool is_regular( const path& p ) { return boost::filesystem::is_regular(p); }
|
||||
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); }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -233,16 +233,81 @@ namespace fc {
|
|||
public:
|
||||
impl( fc::string&s )
|
||||
:ss( reinterpret_cast<std::string&>(s) )
|
||||
{
|
||||
}
|
||||
{ }
|
||||
impl(){}
|
||||
|
||||
std::stringstream ss;
|
||||
};
|
||||
|
||||
stringstream::stringstream( fc::string& s )
|
||||
:my(s) {
|
||||
}
|
||||
stringstream::stringstream(){}
|
||||
stringstream::~stringstream(){}
|
||||
|
||||
stringstream& operator<<( stringstream& s, const int64_t& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const uint64_t& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const int32_t& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const uint32_t& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const int16_t& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const uint16_t& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const int8_t& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const uint8_t& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const float& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const double& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const bool& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const char& v ){
|
||||
s.my->ss << v;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const char* cs ) {
|
||||
s.my->ss << cs;
|
||||
return s;
|
||||
}
|
||||
stringstream& operator<<( stringstream& s, const fc::string& v ){
|
||||
s.my->ss <<reinterpret_cast<const std::string&>(v);
|
||||
return s;
|
||||
}
|
||||
|
||||
fc::string stringstream::str(){
|
||||
//std::string st = my->ss.str();
|
||||
return my->ss.str().c_str();//*reinterpret_cast<fc::string*>(&st);
|
||||
}
|
||||
|
||||
|
||||
stringstream& operator>>( stringstream& s, int64_t& v ){
|
||||
s.my->ss >> v;
|
||||
return s;
|
||||
|
|
|
|||
|
|
@ -64,6 +64,10 @@ namespace fc {
|
|||
void string::clear() { return reinterpret_cast<std::string*>(this)->clear(); }
|
||||
void string::resize( uint64_t s ) { reinterpret_cast<std::string*>(this)->resize(s); }
|
||||
|
||||
|
||||
fc::string string::substr( int32_t start, int32_t len ) {
|
||||
return reinterpret_cast<const std::string&>(*this).substr(start,len).c_str();
|
||||
}
|
||||
const char* string::c_str()const { return reinterpret_cast<const std::string*>(this)->c_str(); }
|
||||
|
||||
bool string::operator == ( const char* s )const {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <fc/tcp_socket.hpp>
|
||||
#include <fc/ip.hpp>
|
||||
#include <fc/fwd_impl.hpp>
|
||||
#include <fc/log.hpp>
|
||||
#include <fc/asio.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
|
@ -9,7 +10,7 @@ namespace fc {
|
|||
public:
|
||||
impl():_sock( fc::asio::default_io_service() ){}
|
||||
~impl(){
|
||||
_sock.cancel();
|
||||
_sock.close();
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::socket _sock;
|
||||
|
|
@ -24,12 +25,14 @@ namespace fc {
|
|||
boost::system::error_code ec;
|
||||
size_t w = my->_sock.write_some( boost::asio::buffer( buf, len ), ec );
|
||||
|
||||
slog( "wrote %d ", w );
|
||||
if( w < len ) {
|
||||
buf += w;
|
||||
len -= w;
|
||||
}
|
||||
}
|
||||
|
||||
if( ec == boost::asio::error::would_block ) {
|
||||
wlog( "world block" );
|
||||
promise<size_t>::ptr p(new promise<size_t>("tcp_socket::write"));
|
||||
boost::asio::async_write( my->_sock, boost::asio::buffer(buf, len),
|
||||
[=]( const boost::system::error_code& ec, size_t bt ) {
|
||||
|
|
@ -38,6 +41,7 @@ namespace fc {
|
|||
});
|
||||
p->wait();
|
||||
} else if( ec ) {
|
||||
wlog( "throw" );
|
||||
throw boost::system::system_error(ec);
|
||||
}
|
||||
}
|
||||
|
|
@ -67,7 +71,7 @@ namespace fc {
|
|||
|
||||
class tcp_server::impl {
|
||||
public:
|
||||
impl():_accept( fc::asio::default_io_service() ){}
|
||||
impl(uint16_t port):_accept( fc::asio::default_io_service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port) ){}
|
||||
~impl(){
|
||||
_accept.cancel();
|
||||
}
|
||||
|
|
@ -75,26 +79,38 @@ namespace fc {
|
|||
boost::asio::ip::tcp::acceptor _accept;
|
||||
};
|
||||
|
||||
tcp_server::tcp_server() {
|
||||
tcp_server::tcp_server(uint16_t port)
|
||||
:my(port) {
|
||||
}
|
||||
tcp_server::~tcp_server() {
|
||||
}
|
||||
|
||||
|
||||
bool tcp_server::accept( tcp_socket& s ) {
|
||||
fc::promise<boost::system::error_code>::ptr p(
|
||||
new promise<boost::system::error_code>("mace::cmt::asio::tcp::accept") );
|
||||
my->_accept.async_accept( s.my->_sock,
|
||||
[=]( const boost::system::error_code& e ) {
|
||||
p->set_value(e);
|
||||
} );
|
||||
slog( "accept!" );
|
||||
fc::promise<boost::system::error_code>::ptr p( new promise<boost::system::error_code>("mace::cmt::asio::tcp::accept") );
|
||||
slog( "." );
|
||||
my->_accept.async_accept( s.my->_sock, [=]( const boost::system::error_code& e ) {
|
||||
slog( "\aaccept!" );
|
||||
p->set_value(e);
|
||||
} );
|
||||
slog( "." );
|
||||
auto ec = p->wait();
|
||||
slog( "." );
|
||||
if( !ec ) s.my->_sock.non_blocking(true);
|
||||
if( ec ) BOOST_THROW_EXCEPTION( boost::system::system_error(ec) );
|
||||
return true;
|
||||
}
|
||||
#if 0
|
||||
void tcp_server::listen( uint16_t port ) {
|
||||
/*
|
||||
slog( "listen %d!", port );
|
||||
my->_accept.bind(
|
||||
slog( "listen %d!", port );
|
||||
my->_accept.listen(port);
|
||||
slog( "listen %d!", port );
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace fc
|
||||
|
|
|
|||
Loading…
Reference in a new issue