Since Communicator is typically used with an EventDispatcher, it can be
inconvenient to just throw exceptions out. Handling them would require
wrapping the EventDispatcher's tick call in a try block, and the exact
source of the exception would be lost.
#include <cstring>
#include "communicator.h"
+using namespace std;
+
namespace {
using namespace Msp::Net;
if(!good)
return;
- in_end += socket.read(in_end, in_buf+buf_size-in_end);
try
{
+ in_end += socket.read(in_end, in_buf+buf_size-in_end);
+
bool more = true;
while(more)
{
}
}
}
- catch(...)
+ catch(const exception &e)
{
good = false;
- throw;
+ if(signal_error.empty())
+ throw;
+ signal_error.emit(e);
}
}
{
public:
sigc::signal<void> signal_handshake_done;
+ sigc::signal<void, const std::exception &> signal_error;
private:
StreamSocket &socket;
if(handshake_status!=2)
throw sequence_error("handshaking not done");
unsigned size = protocol.assemble(pkt, out_buf, buf_size);
- socket.write(out_buf, size);
+ try
+ {
+ socket.write(out_buf, size);
+ }
+ catch(const std::exception &e)
+ {
+ good = false;
+ if(signal_error.empty())
+ throw;
+ signal_error.emit(e);
+ }
}
private: