// InStream::ReceiveHandler implementation virtual void onReceive(const void* data, int size) { std::string key = remoteHost.keyStr(); if (os.isValid()) { // -> already initialized std::string s((char*) data, size); printf("Received %d bytes from %s: %s\n", size, key.c_str(), s.c_str()); server.broadcastMessage(data, size); } else { // -> connect outstream if (size == sizeof(ServiceId)) { ServiceId service = *((ServiceId*) data); printf("Received client callback service id %d from %s\n", service, key.c_str()); os = remoteHost.connect(service); ready = true; sendMessage("HELLO", 6); } else { // invalid init message printf("Received invalid callback service id from %s\n", key.c_str()); is.reset(); server.removeConnection(this); delete this; return; } } is.read(this); }
inline void ReadValue(InStream& in, Type& t) { in.read(reinterpret_cast<char*>(&t), sizeof(Type)); }
Connection(Server& server, const InStream& instream, const Host& host) : is(instream), server(server), remoteHost(host), os(), ready(false) { is.read(this, sizeof(ServiceId)); // read the service id first }
bool getdata(InStream& in, Type& dest) { typedef typename InStream::char_type char_type; in.read(reinterpret_cast<char_type*>(&dest), sizeof(Type)); if (in.gcount() <= 0) return false; return true; }