X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/9145fe7228349a5f457d65f33b7888d2b69b6306..659563a75d668130df84664e7e6b1220667cbc28:/practicas/pipi/src/dev.cpp diff --git a/practicas/pipi/src/dev.cpp b/practicas/pipi/src/dev.cpp index 494d188..d9465a6 100644 --- a/practicas/pipi/src/dev.cpp +++ b/practicas/pipi/src/dev.cpp @@ -16,9 +16,12 @@ struct Frame char frame[1]; }; -Dev::Dev(mac_type mac, size_t mtu, key_t key) throw (std::runtime_error): +Dev::Dev(mac_type mac, size_t mtu, key_t key) + throw (std::runtime_error, std::logic_error): mac(mac), mtu(mtu) { + if (mtu > DEV_MAX_MTU) + throw std::logic_error("MTU más grande que DEV_MAX_MTU"); que_id = msgget(key, 0666); // Debe estar previamente creada if (que_id == -1) throw std::runtime_error("No se pudo crear la cola"); @@ -37,8 +40,8 @@ void Dev::transmit(const std::string& data, const mac_type& mac) memcpy(f->frame, data.c_str(), data.size()); int res = msgsnd(que_id, f, mtu + sizeof(size_t), 0); #ifdef DEBUG - std::cout << "Dev::transmit(msgtype/mac = " << f->mac << ", size = " - << f->size << ", data = " << f->frame << ")\n"; + //std::cout << "Dev::transmit(msgtype/mac = " << f->mac << ", size = " + // << f->size << ")\n"; #endif free(f); if (res == -1) @@ -59,8 +62,8 @@ std::string Dev::receive() throw (std::runtime_error) std::string s((char*) f->frame, f->size); free(f); #ifdef DEBUG - std::cout << "Dev::receive(msgtype/mac = " << mac << ", size = " - << s.size() << ", data = " << s << ")\n"; + //std::cout << "Dev::receive(msgtype/mac = " << mac << ", size = " + // << s.size() << ")\n"; #endif return s; }