X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fcommand_server.cpp;h=cc66de4f58eadd3610eda2dc71d78a1dca9a1333;hp=55c4cc1d865d6cade06b5d4220158fc325c6901c;hb=539b09c0c1819f9394e5a0ae8b3df3687715fa7c;hpb=01a464637ed95b0aacd58eb74bdd17df4a7851ab diff --git a/src/command_server.cpp b/src/command_server.cpp index 55c4cc1..cc66de4 100644 --- a/src/command_server.cpp +++ b/src/command_server.cpp @@ -54,7 +54,7 @@ void command_server::send_hello(unsigned int conn_id) { server_connection* sc=s.get_connection(conn_id); - ostringstream hello; + std::ostringstream hello; hello << "T2Nv" << PROTOCOL_VERSION << ';'; @@ -72,7 +72,7 @@ void command_server::handle_packet(const std::string& packet, server_connection* OBJLOGSTREAM(s,debug,"handling packet from connection " << conn->get_id()); // deserialize packet - istringstream ifs(packet); + std::istringstream ifs(packet); boost::archive::binary_iarchive ia(ifs); command_container ccont; result_container res; @@ -83,7 +83,7 @@ void command_server::handle_packet(const std::string& packet, server_connection* } catch(boost::archive::archive_exception &e) { - ostringstream msg; + std::ostringstream msg; msg << "archive_exception while deserializing on server-side, " "code " << e.code << " (" << e.what() << ")"; res.set_exception(new t2n_serialization_error(msg.str())); @@ -101,8 +101,7 @@ void command_server::handle_packet(const std::string& packet, server_connection* xo << BOOST_SERIALIZATION_NVP(ccont); } - // TODO: cast to command subclass (template) - command *cmd=ccont.get_command(); + command* cmd=cast_command(ccont.get_command()); if (cmd) { @@ -116,10 +115,17 @@ void command_server::handle_packet(const std::string& packet, server_connection* { throw; } } else - throw logic_error("uninitialized command called"); + { + std::ostringstream msg; + if (ccont.get_command()!=NULL) + msg << "illegal command of type " << typeid(ccont.get_command()).name() << " called"; + else + msg << "NULL command called"; + res.set_exception(new t2n_command_error(msg.str())); + } } - ostringstream ofs; + std::ostringstream ofs; boost::archive::binary_oarchive oa(ofs); try @@ -128,7 +134,7 @@ void command_server::handle_packet(const std::string& packet, server_connection* } catch(boost::archive::archive_exception &e) { - ostringstream msg; + std::ostringstream msg; msg << "archive_exception while serializing on server-side, " "code " << e.code << " (" << e.what() << ")"; res.set_exception(new t2n_serialization_error(msg.str())); @@ -156,7 +162,7 @@ void command_server::handle(long long usec_timeout, long long* usec_timeout_rema { if (s.fill_buffer(usec_timeout,usec_timeout_remaining)) { - string packet; + std::string packet; unsigned int conn_id; while (s.get_packet(packet,conn_id))