Merge branch 'phoenix' of https://github.com/InvictusInnovations/fc into phoenix
This commit is contained in:
commit
ab31df2e9f
5 changed files with 44 additions and 8 deletions
|
|
@ -37,6 +37,10 @@ namespace fc {
|
||||||
inline microseconds hours(int64_t h) { return minutes(60*h); }
|
inline microseconds hours(int64_t h) { return minutes(60*h); }
|
||||||
inline microseconds days(int64_t d) { return hours(24*d); }
|
inline microseconds days(int64_t d) { return hours(24*d); }
|
||||||
|
|
||||||
|
class variant;
|
||||||
|
void to_variant( const fc::microseconds&, fc::variant& );
|
||||||
|
void from_variant( const fc::variant& , fc::microseconds& );
|
||||||
|
|
||||||
class time_point {
|
class time_point {
|
||||||
public:
|
public:
|
||||||
explicit time_point( microseconds e = microseconds() ) :elapsed(e){}
|
explicit time_point( microseconds e = microseconds() ) :elapsed(e){}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ namespace fc
|
||||||
class mutable_variant_object;
|
class mutable_variant_object;
|
||||||
class time_point;
|
class time_point;
|
||||||
class time_point_sec;
|
class time_point_sec;
|
||||||
|
class microseconds;
|
||||||
|
|
||||||
void to_variant( const int16_t& var, variant& vo );
|
void to_variant( const int16_t& var, variant& vo );
|
||||||
void from_variant( const variant& var, int16_t& vo );
|
void from_variant( const variant& var, int16_t& vo );
|
||||||
|
|
@ -69,6 +70,10 @@ namespace fc
|
||||||
|
|
||||||
void to_variant( const time_point_sec& var, variant& vo );
|
void to_variant( const time_point_sec& var, variant& vo );
|
||||||
void from_variant( const variant& var, time_point_sec& vo );
|
void from_variant( const variant& var, time_point_sec& vo );
|
||||||
|
|
||||||
|
void to_variant( const microseconds& input_microseconds, variant& output_variant );
|
||||||
|
void from_variant( const variant& input_variant, microseconds& output_microseconds );
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
void to_variant( size_t s, variant& v );
|
void to_variant( size_t s, variant& v );
|
||||||
#elif !defined(_MSC_VER)
|
#elif !defined(_MSC_VER)
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,11 @@ namespace fc
|
||||||
{
|
{
|
||||||
return token.str();
|
return token.str();
|
||||||
}
|
}
|
||||||
|
catch (const std::ios_base::failure&)
|
||||||
|
{
|
||||||
|
return token.str();
|
||||||
|
}
|
||||||
|
|
||||||
FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
|
FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
|
||||||
("token", token.str() ) );
|
("token", token.str() ) );
|
||||||
}
|
}
|
||||||
|
|
@ -179,6 +184,10 @@ namespace fc
|
||||||
catch( const fc::eof_exception& e )
|
catch( const fc::eof_exception& e )
|
||||||
{
|
{
|
||||||
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF: ${e}", ("e", e.to_detail_string() ) );
|
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF: ${e}", ("e", e.to_detail_string() ) );
|
||||||
|
}
|
||||||
|
catch( const std::ios_base::failure& e )
|
||||||
|
{
|
||||||
|
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF: ${e}", ("e", e.what() ) );
|
||||||
} FC_RETHROW_EXCEPTIONS( warn, "Error parsing object" );
|
} FC_RETHROW_EXCEPTIONS( warn, "Error parsing object" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,6 +270,9 @@ namespace fc
|
||||||
catch (fc::eof_exception&)
|
catch (fc::eof_exception&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
catch (const std::ios_base::failure&)
|
||||||
|
{
|
||||||
|
}
|
||||||
fc::string str = ss.str();
|
fc::string str = ss.str();
|
||||||
if (str == "-." || str == ".") // check the obviously wrong things we could have encountered
|
if (str == "-." || str == ".") // check the obviously wrong things we could have encountered
|
||||||
FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str));
|
FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str));
|
||||||
|
|
@ -306,6 +318,10 @@ namespace fc
|
||||||
{
|
{
|
||||||
received_eof = true;
|
received_eof = true;
|
||||||
}
|
}
|
||||||
|
catch (const std::ios_base::failure&)
|
||||||
|
{
|
||||||
|
received_eof = true;
|
||||||
|
}
|
||||||
|
|
||||||
// we can get here either by processing a delimiter as in "null,"
|
// we can get here either by processing a delimiter as in "null,"
|
||||||
// an EOF like "null<EOF>", or an invalid token like "nullZ"
|
// an EOF like "null<EOF>", or an invalid token like "nullZ"
|
||||||
|
|
@ -391,11 +407,11 @@ namespace fc
|
||||||
return variant();
|
return variant();
|
||||||
}
|
}
|
||||||
variant json::from_string( const std::string& utf8_str )
|
variant json::from_string( const std::string& utf8_str )
|
||||||
{
|
{ try {
|
||||||
std::stringstream in( utf8_str );
|
fc::stringstream in( utf8_str );
|
||||||
in.exceptions( std::ifstream::eofbit );
|
//in.exceptions( std::ifstream::eofbit );
|
||||||
return variant_from_stream( in );
|
return variant_from_stream( in );
|
||||||
}
|
} FC_RETHROW_EXCEPTIONS( warn, "", ("str",utf8_str) ) }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void toUTF8( const char str, ostream& os )
|
void toUTF8( const char str, ostream& os )
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include <fc/log/logger.hpp>
|
#include <fc/log/logger.hpp>
|
||||||
#include <fc/io/stdio.hpp>
|
#include <fc/io/stdio.hpp>
|
||||||
#include <fc/network/url.hpp>
|
#include <fc/network/url.hpp>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
|
|
||||||
class fc::http::connection::impl
|
class fc::http::connection::impl
|
||||||
|
|
@ -55,7 +56,7 @@ class fc::http::connection::impl
|
||||||
while( *end != '\r' ) ++end;
|
while( *end != '\r' ) ++end;
|
||||||
h.val = fc::string(skey,end);
|
h.val = fc::string(skey,end);
|
||||||
rep.headers.push_back(h);
|
rep.headers.push_back(h);
|
||||||
if( h.key == "Content-Length" ) {
|
if( boost::iequals(h.key, "Content-Length") ) {
|
||||||
rep.body.resize( static_cast<size_t>(to_uint64( fc::string(h.val) ) ));
|
rep.body.resize( static_cast<size_t>(to_uint64( fc::string(h.val) ) ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -151,12 +152,12 @@ http::request connection::read_request()const {
|
||||||
while( *end != '\r' ) ++end;
|
while( *end != '\r' ) ++end;
|
||||||
h.val = fc::string(skey,end);
|
h.val = fc::string(skey,end);
|
||||||
req.headers.push_back(h);
|
req.headers.push_back(h);
|
||||||
if( h.key == "Content-Length" ) {
|
if( boost::iequals(h.key, "Content-Length")) {
|
||||||
auto s = static_cast<size_t>(to_uint64( fc::string(h.val) ) );
|
auto s = static_cast<size_t>(to_uint64( fc::string(h.val) ) );
|
||||||
FC_ASSERT( s < 1024*1024 );
|
FC_ASSERT( s < 1024*1024 );
|
||||||
req.body.resize( static_cast<size_t>(to_uint64( fc::string(h.val) ) ));
|
req.body.resize( static_cast<size_t>(to_uint64( fc::string(h.val) ) ));
|
||||||
}
|
}
|
||||||
if( h.key == "Host" ) {
|
if( boost::iequals(h.key, "Host") ) {
|
||||||
req.domain = h.val;
|
req.domain = h.val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
src/time.cpp
12
src/time.cpp
|
|
@ -99,4 +99,14 @@ namespace fc {
|
||||||
string get_approximate_relative_time_string(const time_point& event_time) {
|
string get_approximate_relative_time_string(const time_point& event_time) {
|
||||||
return get_approximate_relative_time_string(time_point_sec(event_time));
|
return get_approximate_relative_time_string(time_point_sec(event_time));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void to_variant( const microseconds& input_microseconds, variant& output_variant )
|
||||||
|
{
|
||||||
|
output_variant = input_microseconds.count();
|
||||||
|
}
|
||||||
|
void from_variant( const variant& input_variant, microseconds& output_microseconds )
|
||||||
|
{
|
||||||
|
output_microseconds = microseconds(input_variant.as_int64());
|
||||||
|
}
|
||||||
|
|
||||||
|
} //namespace fc
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue