#include <cstring>
#include "communicator.h"
+#include "streamsocket.h"
+
+using namespace std;
namespace {
handshake_status = 1;
}
+void Communicator::send_data(unsigned size)
+{
+ if(!good)
+ throw sequence_error("connection aborted");
+ if(handshake_status!=2)
+ throw sequence_error("handshake incomplete");
+
+ try
+ {
+ socket.write(out_buf, size);
+ }
+ catch(const std::exception &e)
+ {
+ good = false;
+ if(signal_error.empty())
+ throw;
+ signal_error.emit(e);
+ }
+}
+
void Communicator::data_available()
{
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);
}
}
{
char *pkt = in_begin;
in_begin += psz;
- proto.disassemble(recv, pkt, psz);
+ proto.dispatch(recv, pkt, psz);
return true;
}
else
shake.hash = protocol.get_hash();
HandshakeProtocol hsproto;
- unsigned size = hsproto.assemble(shake, out_buf, buf_size);
+ unsigned size = hsproto.serialize(shake, out_buf, buf_size);
socket.write(out_buf, size);
}