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)
32 std::cout << "DevQue[" << que_id << "]::transmit()\n";
34 if (data.size() > mtu)
35 throw std::logic_error("Tamaño de datos mayor al MTU");
36 Frame* f = (Frame*) malloc(sizeof(Frame) + mtu);
38 throw std::runtime_error("No se puede reservar memoria");
40 f->size = data.size();
41 memcpy(f->frame, data.data(), data.size());
42 int res = msgsnd(que_id, f, mtu + sizeof(size_t), 0);
44 std::cout << "DevQue[" << que_id << "]::transmit(msgtype/mac = "
45 << f->mac << ", size = " << f->size << ")\n";
49 throw std::runtime_error("Error al poner en la cola");
52 std::string DevQue::receive() throw (std::runtime_error)
55 std::cout << "DevQue[" << que_id << "]::receive()\n";
60 std::string DevQue::receive(mac_type& mac) throw (std::runtime_error)
63 std::cout << "DevQue[" << que_id << "]::receive(mac)\n";
65 Frame* f = (Frame*) malloc(sizeof(Frame) + mtu);
67 throw std::runtime_error("No se puede reservar memoria");
68 int res = msgrcv(que_id, f, mtu + sizeof(size_t), mac, 0);
72 throw std::runtime_error("Error al sacar de la cola");
74 std::string s((char*) f->frame, f->size);
79 std::cout << "DevQue[" << que_id << "]::receive(msgtype/mac = "
80 << mac << ", size = " << s.size() << ")\n";
85 /// Indica cuantos elementos hay en la cola
86 size_t DevQue::size() const
88 struct msqid_ds minfo;
89 msgctl(que_id, IPC_STAT, &minfo);
90 return minfo.msg_qnum;
93 /// Indica si está vacía la cola
94 bool DevQue::empty() const
99 // vim: set et sw=4 sts=4 :