00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00035 #include "tp.h"
00036 #include "threadsafe_db.h"
00037 #include "logfile.h"
00038
00039 namespace protlib {
00040
00046 using namespace log;
00047
00048
00049
00050
00057 TP::TP(protocol_t p, const string& pname, const string& tpn,
00058 const unsigned short common_header_length,
00059 bool (*const getmsglength)(NetMsg& netmsg, uint32& msglen),
00060 uint32 mp)
00061 : protocol(p), protoname(pname), tp_name(tpn),
00062 common_header_length(common_header_length),
00063 getmsglength(getmsglength),
00064 init(false),
00065 max_payload((mp<NetMsg::max_size)?mp:(NetMsg::max_size))
00066 {}
00067
00069 TP::~TP() { init = false; }
00070
00072 protocol_t TP::get_underlying_protocol() const { return protocol; }
00073
00075 string TP::get_underlying_protocol_name() const { return protoname; }
00076
00078 string TP::get_tp_name() const { return tp_name; }
00079
00080 uint32 TP::get_max_payload() const { return max_payload; }
00081
00082
00083
00084
00085
00086
00087 void TP::check_send_args(const NetMsg& msg, const address& addr)
00088 const {
00089 if (!init) {
00090 Log(ERROR_LOG,LOG_NORMAL, "TP", "TP::check_send_args: " << tp_name << " not initialized");
00091 throw TPErrorArgsNotInit();
00092 }
00093
00094 if ((msg.get_size()==0) || (msg.get_size()>max_payload)) {
00095 Log(ERROR_LOG,LOG_NORMAL, "TP", "TP::check_send_args: NetMsg empty or too big. Size: " << msg.get_size() << ", " << tp_name << ", max_payload " << max_payload);
00096 throw TPErrorPayload();
00097 }
00098
00099 }
00100
00101
00103
00104 }