19 Dev::Dev(mac_type mac, key_t key, size_t mtu)
20 throw (std::runtime_error, std::logic_error):
23 if (mtu > DEV_MAX_MTU)
24 throw std::logic_error("MTU más grande que DEV_MAX_MTU");
25 que_id = msgget(key, 0666); // Debe estar previamente creada
27 throw std::runtime_error("No se pudo crear la cola");
30 void Dev::transmit(const std::string& data, const mac_type& mac)
31 throw (std::runtime_error, std::logic_error)
33 if (data.size() > mtu)
34 throw std::logic_error("Tamaño de datos mayor al MTU");
35 Frame* f = (Frame*) malloc(sizeof(Frame) + mtu);
37 throw std::runtime_error("No se puede reservar memoria");
39 f->size = data.size();
40 memcpy(f->frame, data.c_str(), data.size());
41 int res = msgsnd(que_id, f, mtu + sizeof(size_t), 0);
43 //std::cout << "Dev::transmit(msgtype/mac = " << f->mac << ", size = "
44 // << f->size << ")\n";
48 throw std::runtime_error("Error al poner en la cola");
51 std::string Dev::receive() throw (std::runtime_error)
53 Frame* f = (Frame*) malloc(sizeof(Frame) + mtu);
55 throw std::runtime_error("No se puede reservar memoria");
56 int res = msgrcv(que_id, f, mtu + sizeof(size_t), mac, 0);
60 throw std::runtime_error("Error al sacar de la cola");
62 std::string s((char*) f->frame, f->size);
65 //std::cout << "Dev::receive(msgtype/mac = " << mac << ", size = "
66 // << s.size() << ")\n";
71 // vim: set et sw=4 sts=4 :