19 Dev::Dev(mac_type mac, size_t mtu, key_t key) throw (std::runtime_error):
22 que_id = msgget(key, 0666); // Debe estar previamente creada
24 throw std::runtime_error("No se pudo crear la cola");
27 void Dev::transmit(const std::string& data, const mac_type& mac)
28 throw (std::runtime_error, std::logic_error)
30 if (data.size() > mtu)
31 throw std::logic_error("Tamaño de datos mayor al MTU");
32 Frame* f = (Frame*) malloc(sizeof(Frame) + mtu);
34 throw std::runtime_error("No se puede reservar memoria");
36 f->size = data.size();
37 memcpy(f->frame, data.c_str(), data.size());
38 int res = msgsnd(que_id, f, mtu + sizeof(size_t), 0);
40 std::cout << "Dev::transmit(msgtype/mac = " << f->mac << ", size = "
41 << f->size << ", data = " << f->frame << ")\n";
45 throw std::runtime_error("Error al poner en la cola");
48 std::string Dev::receive() throw (std::runtime_error)
50 Frame* f = (Frame*) malloc(sizeof(Frame) + mtu);
52 throw std::runtime_error("No se puede reservar memoria");
53 int res = msgrcv(que_id, f, mtu + sizeof(size_t), mac, 0);
57 throw std::runtime_error("Error al sacar de la cola");
59 std::string s((char*) f->frame, f->size);
62 std::cout << "Dev::receive(msgtype/mac = " << mac << ", size = "
63 << s.size() << ", data = " << s << ")\n";
68 // vim: set et sw=4 sts=4 :