Fixed error_report to_string
Updated fc::datastream and base64 to use error_report Added url to cmake lists various other bug fixes
This commit is contained in:
parent
8612a98149
commit
9a8767a645
8 changed files with 44 additions and 21 deletions
|
|
@ -48,6 +48,7 @@ include_directories( include )
|
|||
|
||||
set( sources
|
||||
src/ssh.cpp
|
||||
src/url.cpp
|
||||
src/process.cpp
|
||||
src/http_connection.cpp
|
||||
src/http_server.cpp
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _FC_DATASTREAM_HPP_
|
||||
#define _FC_DATASTREAM_HPP_
|
||||
#include <fc/utility.hpp>
|
||||
#include <fc/exception.hpp>
|
||||
#include <fc/error_report.hpp>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
@ -40,8 +40,8 @@ struct datastream {
|
|||
m_pos += s;
|
||||
return true;
|
||||
}
|
||||
FC_THROW_MSG( "Attempt to read %s bytes beyond end of buffer of size %s",
|
||||
int64_t(-((m_end-m_pos) - s)), int64_t(m_end-m_start) );
|
||||
FC_THROW_REPORT( "Attempt to read ${bytes_past} bytes beyond end of buffer with size ${buffer_size} ",
|
||||
fc::value().set("bytes_past",int64_t(-((m_end-m_pos) - s))).set("buffer_size", int64_t(m_end-m_start)) );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +51,8 @@ struct datastream {
|
|||
m_pos += s;
|
||||
return true;
|
||||
}
|
||||
FC_THROW_MSG( "Attempt to write %s bytes beyond end of buffer of size %s", int64_t(-((m_end-m_pos) - s)),int64_t(m_end-m_start) );
|
||||
FC_THROW_REPORT( "Attempt to write ${bytes_past} bytes beyond end of buffer with size ${buffer_size} ",
|
||||
fc::value().set("bytes_past",int64_t(-((m_end-m_pos) - s))).set("buffer_size", int64_t(m_end-m_start)) );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +62,8 @@ struct datastream {
|
|||
++m_pos;
|
||||
return true;
|
||||
}
|
||||
FC_THROW_MSG( "Attempt to write %s byte beyond end of buffer of size %s", int64_t(-((m_end-m_pos) - 1)), int64_t(m_end-m_start) );
|
||||
FC_THROW_REPORT( "Attempt to write ${bytes_past} bytes beyond end of buffer with size ${buffer_size} ",
|
||||
fc::value().set("bytes_past",int64_t(-((m_end-m_pos) - 1))).set("buffer_size", int64_t(m_end-m_start)) );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +74,8 @@ struct datastream {
|
|||
++m_pos;
|
||||
return true;
|
||||
}
|
||||
FC_THROW_MSG( "Attempt to read %s byte beyond end of buffer of size %s", int64_t(-((m_end-m_pos) - 1)), int64_t(m_end-m_start) );
|
||||
FC_THROW_REPORT( "Attempt to read ${bytes_past} bytes beyond end of buffer of size ${buffer_size} ",
|
||||
fc::value().set("bytes_past",int64_t(-((m_end-m_pos) - 1))).set("buffer_size", int64_t(m_end-m_start)) );
|
||||
++m_pos;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,12 +61,13 @@ namespace fc {
|
|||
public:
|
||||
template<typename Functor>
|
||||
task( Functor&& f ):task_base(&_functor) {
|
||||
typedef typename fc::deduce<Functor>::type FunctorType;
|
||||
static_assert( sizeof(f) <= sizeof(_functor), "sizeof(Functor) is larger than FunctorSize" );
|
||||
new ((char*)&_functor) Functor( fc::forward<Functor>(f) );
|
||||
_destroy_functor = &detail::functor_destructor<Functor>::destroy;
|
||||
new ((char*)&_functor) FunctorType( fc::forward<Functor>(f) );
|
||||
_destroy_functor = &detail::functor_destructor<FunctorType>::destroy;
|
||||
|
||||
_promise_impl = static_cast<promise<R>*>(this);
|
||||
_run_functor = &detail::functor_run<Functor>::run;
|
||||
_run_functor = &detail::functor_run<FunctorType>::run;
|
||||
}
|
||||
aligned<FunctorSize> _functor;
|
||||
private:
|
||||
|
|
@ -77,12 +78,13 @@ namespace fc {
|
|||
public:
|
||||
template<typename Functor>
|
||||
task( Functor&& f ):task_base(&_functor) {
|
||||
typedef typename fc::deduce<Functor>::type FunctorType;
|
||||
static_assert( sizeof(f) <= sizeof(_functor), "sizeof(Functor) is larger than FunctorSize" );
|
||||
new ((char*)&_functor) Functor( fc::forward<Functor>(f) );
|
||||
_destroy_functor = &detail::functor_destructor<Functor>::destroy;
|
||||
new ((char*)&_functor) FunctorType( fc::forward<Functor>(f) );
|
||||
_destroy_functor = &detail::functor_destructor<FunctorType>::destroy;
|
||||
|
||||
_promise_impl = static_cast<promise<void>*>(this);
|
||||
_run_functor = &detail::void_functor_run<Functor>::run;
|
||||
_run_functor = &detail::void_functor_run<FunctorType>::run;
|
||||
}
|
||||
aligned<FunctorSize> _functor;
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -52,8 +52,9 @@ namespace fc {
|
|||
template<typename Functor>
|
||||
auto async( Functor&& f, const char* desc ="", priority prio = priority()) -> fc::future<decltype(f())> {
|
||||
typedef decltype(f()) Result;
|
||||
fc::task<Result,sizeof(Functor)>* tsk =
|
||||
new fc::task<Result,sizeof(Functor)>( fc::forward<Functor>(f) );
|
||||
typedef typename fc::deduce<Functor>::type FunctorType;
|
||||
fc::task<Result,sizeof(FunctorType)>* tsk =
|
||||
new fc::task<Result,sizeof(FunctorType)>( fc::forward<Functor>(f) );
|
||||
fc::future<Result> r(fc::shared_ptr< fc::promise<Result> >(tsk,true) );
|
||||
async_task(tsk,prio,desc);
|
||||
return r;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include <fc/log.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/exception.hpp>
|
||||
#include <fc/error_report.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
|
@ -616,7 +617,7 @@ size_t from_base58( const fc::string& base58_str, char* out_data, size_t out_dat
|
|||
//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 );
|
||||
FC_THROW_REPORT( "Unable to decode base58 string ${base58_str}", fc::value().set("base58_str",base58_str) );
|
||||
}
|
||||
|
||||
memcpy( out_data, out.data(), out.size() );
|
||||
|
|
|
|||
|
|
@ -86,8 +86,9 @@ fc::string error_frame::to_string()const {
|
|||
int64_t prev = 0;
|
||||
auto next = desc.find( '$' );
|
||||
while( prev != int64_t(fc::string::npos) && prev < int64_t(desc.size()) ) {
|
||||
// slog( "prev: %d next %d %s", prev, next, desc.substr(prev,next).c_str() );
|
||||
// print everything from the last pos until the first '$'
|
||||
ss << desc.substr( prev, next );
|
||||
ss << desc.substr( prev, next-prev );
|
||||
|
||||
// if we got to the end, return it.
|
||||
if( next == string::npos ) { return ss.str(); }
|
||||
|
|
@ -102,6 +103,7 @@ fc::string error_frame::to_string()const {
|
|||
if( next != fc::string::npos ) {
|
||||
// the key is between prev and next
|
||||
fc::string key = desc.substr( prev+1, (next-prev-1) );
|
||||
//slog( "key '%s'", key.c_str() );
|
||||
if( meta ) {
|
||||
auto itr = meta->find( key.c_str() );
|
||||
if( itr != meta->end() ) {
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ namespace fc { namespace http {
|
|||
try {
|
||||
http::connection con;
|
||||
while( tcp_serv.accept( con.get_socket() ) ) {
|
||||
slog( "Accept Connection" );
|
||||
fc::async( [=](){ handle_connection( con, on_req ); } );
|
||||
con = http::connection();
|
||||
}
|
||||
|
|
@ -66,9 +67,14 @@ namespace fc { namespace http {
|
|||
|
||||
void handle_connection( const http::connection& c,
|
||||
std::function<void(const http::request&, const server::response& s )> do_on_req ) {
|
||||
wlog( "reading request.." );
|
||||
try {
|
||||
http::server::response rep( fc::shared_ptr<response::impl>( new response::impl(c, [=](){ this->handle_connection(c,do_on_req); } ) ) );
|
||||
auto req = c.read_request();
|
||||
if( do_on_req ) do_on_req( req, rep );
|
||||
} catch ( ... ) {
|
||||
wlog( "unable to read request %s", fc::except_str().c_str());
|
||||
}
|
||||
}
|
||||
std::function<void(const http::request&, const server::response& s )> on_req;
|
||||
fc::tcp_server tcp_serv;
|
||||
|
|
@ -126,6 +132,13 @@ namespace fc { namespace http {
|
|||
}
|
||||
my->body_bytes_sent += len;
|
||||
my->con.get_socket().write( data, len );
|
||||
if( my->body_bytes_sent == int64_t(my->body_length) ) {
|
||||
if( my->handle_next_req ) {
|
||||
slog( "handle next request..." );
|
||||
//fc::async( std::function<void()>(my->handle_next_req) );
|
||||
fc::async( my->handle_next_req );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server::response::~response(){}
|
||||
|
|
|
|||
Loading…
Reference in a new issue