19 DevQue::DevQue(mac_type mac, key_t key, size_t mtu)
20 throw (std::runtime_error, std::logic_error):
23 que_id = msgget(key, IPC_CREAT | 0666);
25 throw std::runtime_error("No se pudo crear la cola");
28 void DevQue::transmit(const std::string& data, const mac_type& mac)
29 throw (std::runtime_error, std::logic_error)
31 if (data.size() > mtu)
32 throw std::logic_error("Tamaño de datos mayor al MTU");
33 Frame* f = (Frame*) malloc(sizeof(Frame) + mtu);
35 throw std::runtime_error("No se puede reservar memoria");
37 f->size = data.size();
38 memcpy(f->frame, data.c_str(), data.size());
39 int res = msgsnd(que_id, f, mtu + sizeof(size_t), 0);
41 std::cout << "DevQue::transmit(msgtype/mac = " << f->mac << ", size = "
46 throw std::runtime_error("Error al poner en la cola");
49 std::string DevQue::receive() throw (std::runtime_error)
54 std::string DevQue::receive(mac_type& mac) throw (std::runtime_error)
56 Frame* f = (Frame*) malloc(sizeof(Frame) + mtu);
58 throw std::runtime_error("No se puede reservar memoria");
59 int res = msgrcv(que_id, f, mtu + sizeof(size_t), mac, 0);
63 throw std::runtime_error("Error al sacar de la cola");
65 std::string s((char*) f->frame, f->size);
70 std::cout << "DevQue::receive(msgtype/mac = " << mac << ", size = "
76 /// Indica cuantos elementos hay en la cola
77 size_t DevQue::size() const
79 struct msqid_ds minfo;
80 msgctl(que_id, IPC_STAT, &minfo);
81 return minfo.msg_qnum;
84 /// Indica si está vacía la cola
85 bool DevQue::empty() const
90 // vim: set et sw=4 sts=4 :