numerous bug fixes

This commit is contained in:
Daniel Larimer 2012-11-24 13:02:23 -05:00
parent 3fb9857504
commit 4812477ea6
4 changed files with 19 additions and 11 deletions

View file

@ -168,17 +168,19 @@ namespace fc {
future( shared_ptr<promise<T>>&& p ):m_prom(fc::move(p)){} future( shared_ptr<promise<T>>&& p ):m_prom(fc::move(p)){}
future(){} future(){}
operator const T&()const { return wait(); }
/// @pre valid() /// @pre valid()
/// @post ready() /// @post ready()
/// @throws timeout /// @throws timeout
const T& wait( const microseconds& timeout = microseconds::max() ){ const T& wait( const microseconds& timeout = microseconds::max() )const {
return m_prom->wait(timeout); return m_prom->wait(timeout);
} }
/// @pre valid() /// @pre valid()
/// @post ready() /// @post ready()
/// @throws timeout /// @throws timeout
const T& wait_until( const time_point& tp ) { const T& wait_until( const time_point& tp )const {
return m_prom->wait_until(tp); return m_prom->wait_until(tp);
} }

View file

@ -31,6 +31,7 @@ namespace fc {
} }
struct impl_base : public fc::retainable { struct impl_base : public fc::retainable {
virtual ~impl_base(){}
virtual void write( const char* buf, size_t len ) = 0; virtual void write( const char* buf, size_t len ) = 0;
virtual void close() = 0; virtual void close() = 0;
virtual void flush() = 0; virtual void flush() = 0;
@ -85,9 +86,10 @@ namespace fc {
protected: protected:
struct impl_base : public fc::retainable { struct impl_base : public fc::retainable {
virtual void read( char* buf, size_t len ) = 0; virtual ~impl_base(){}
virtual size_t readsome( char* buf, size_t len ) = 0; virtual void read( char* buf, size_t len )=0;
virtual bool eof()const; virtual size_t readsome( char* buf, size_t len )=0;
virtual bool eof()const=0;
}; };
template<typename T> template<typename T>

View file

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <fc/json_rpc_client.hpp> #include <fc/json_rpc_client.hpp>
#include <fc/json_rpc_stream_connection.hpp>
#include <fc/process.hpp> #include <fc/process.hpp>
#include <fc/filesystem.hpp>
namespace fc { namespace json { namespace fc { namespace json {
@ -9,7 +11,7 @@ namespace fc { namespace json {
public: public:
fc::future<int> exec( const fc::path& exe, int opt = fc::process::open_all ) { fc::future<int> exec( const fc::path& exe, int opt = fc::process::open_all ) {
return exec( exe, fc::path(), opt ); return exec( exe, fc::path("."), opt );
} }
fc::future<int> exec( const fc::path& exe, const fc::path& wd, fc::future<int> exec( const fc::path& exe, const fc::path& wd,
int opt = fc::process::open_all ) { int opt = fc::process::open_all ) {
@ -17,14 +19,16 @@ namespace fc { namespace json {
} }
fc::future<int> exec( const fc::path& exe, fc::vector<fc::string>&& args , fc::future<int> exec( const fc::path& exe, fc::vector<fc::string>&& args ,
int opt = fc::process::open_all ) { int opt = fc::process::open_all ) {
return exec( exe, fc::move(args), fc::path(), opt ); return exec( exe, fc::move(args), fc::path("."), opt );
} }
fc::future<int> exec( const fc::path& exe, fc::vector<fc::string>&& args, fc::future<int> exec( const fc::path& exe, fc::vector<fc::string>&& args,
const fc::path& wd, int opt = fc::process::open_all ) { const fc::path& wd, int opt = fc::process::open_all ) {
auto r = _proc.exec( exe, fc::move(args), wd, opt ); slog( "cd %s; %s", wd.generic_string().c_str(), exe.generic_string().c_str() );
auto r = _proc.exec( canonical(exe), fc::move(args), wd, opt );
_con.reset( new fc::json::rpc_stream_connection( _proc.out_stream(), _proc.in_stream() ) ); _con.reset( new fc::json::rpc_stream_connection( _proc.out_stream(), _proc.in_stream() ) );
this->_vtable.reset(new fc::detail::vtable<InterfaceType,fc::json::detail::rpc_member>() ); this->_vtable.reset(new fc::detail::vtable<InterfaceType,fc::json::detail::rpc_member>() );
this->_vtable->template visit<InterfaceType>( fc::json::detail::vtable_visitor(_con) ); rpc_connection::ptr p(_con);
this->_vtable->template visit_other<InterfaceType>( fc::json::detail::vtable_visitor(p) );
return r; return r;
} }
@ -35,7 +39,7 @@ namespace fc { namespace json {
*/ */
fc::istream& err_stream() { return _proc.err_stream(); } fc::istream& err_stream() { return _proc.err_stream(); }
template<typename T&&> template<typename T>
void on_close( T&& f) { _con->on_close( fc::forward<T>(f) ); } void on_close( T&& f) { _con->on_close( fc::forward<T>(f) ); }
private: private:

View file

@ -133,7 +133,7 @@ fc::future<int> process::exec( const fc::path& exe, fc::vector<fc::string>&& arg
promise<int>::ptr p(new promise<int>("process")); promise<int>::ptr p(new promise<int>("process"));
my->stat.async_wait( my->child->get_id(), [=]( const boost::system::error_code& ec, int exit_code ) my->stat.async_wait( my->child->get_id(), [=]( const boost::system::error_code& ec, int exit_code )
{ {
slog( "process::result %1%", exit_code ); slog( "process::result %d", exit_code );
if( !ec ) { if( !ec ) {
#ifdef BOOST_POSIX_API #ifdef BOOST_POSIX_API
try { try {