update tcp / http error reporting

This commit is contained in:
Daniel Larimer 2013-01-04 12:35:17 -08:00
parent 533dd28d67
commit 6742f63256
3 changed files with 15 additions and 9 deletions

View file

@ -12,6 +12,7 @@ namespace fc {
bool operator==(const microseconds& c)const { return _count == c._count; }
friend bool operator>(const microseconds& a, const microseconds& b){ return a._count > b._count; }
friend bool operator<(const microseconds& a, const microseconds& b){ return a._count < b._count; }
microseconds& operator+=(const microseconds& c) { _count += c._count; return *this; }
int64_t count()const { return _count; }
private:

View file

@ -33,7 +33,7 @@ FC_START_SHARED_IMPL(fc::http::connection)
fc::http::reply parse_reply() {
fc::http::reply rep;
//try {
try {
fc::vector<char> line(1024*8);
int s = read_until( line.data(), line.data()+line.size(), ' ' ); // HTTP/1.1
s = read_until( line.data(), line.data()+line.size(), ' ' ); // CODE
@ -56,16 +56,17 @@ FC_START_SHARED_IMPL(fc::http::connection)
}
}
if( rep.body.size() ) {
slog( "Reading body size %d", rep.body.size() );
//slog( "Reading body size %d", rep.body.size() );
sock.read( rep.body.data(), rep.body.size() );
}
return rep;
/* } catch ( ... ) {
} catch ( ... ) {
elog( "%s", fc::except_str().c_str() );
sock.close();
FC_THROW_REPORT( "Error parsing reply" );
rep.status = http::reply::InternalServerError;
return rep;
} */
}
}
FC_END_SHARED_IMPL
@ -92,7 +93,7 @@ http::reply connection::request( const fc::string& method,
wlog( "Re-open socket!" );
my->sock.connect_to( my->ep );
}
//try {
try {
fc::stringstream req;
req << method <<" "<<url<<" HTTP/1.1\r\n";
req << "Host: localhost\r\n";
@ -111,10 +112,11 @@ http::reply connection::request( const fc::string& method,
// fc::cerr.flush();
return my->parse_reply();
// } catch ( ... ) {
// my->sock.close();
} catch ( ... ) {
my->sock.close();
FC_THROW_REPORT( "Error Sending HTTP Request" ); // TODO: provide more info
// return http::reply( http::reply::InternalServerError ); // TODO: replace with connection error
// }
}
}
// used for servers

View file

@ -1,4 +1,5 @@
#include <fc/tcp_socket.hpp>
#include <fc/hex.hpp>
#include <fc/ip.hpp>
#include <fc/fwd_impl.hpp>
#include <fc/log.hpp>
@ -52,7 +53,9 @@ namespace fc {
p->wait();
} else if( ec ) {
elog( "throw... write data failed %s", boost::system::system_error(ec).what() );
throw boost::system::system_error(ec);
FC_THROW_REPORT( "Failed to write data to tcp socket",
fc::value().set("reason", fc::string(boost::system::system_error(ec).what()))
.set("data", fc::to_hex(buf,len) ) );
}
return *this;
}