//--------------------------------------------------------- // com.mq.cc //--------------------------------------------------------- #include "check.h" #include #include #include #include #include //--------------------------------------------------------- int main() { const unsigned N = 64; const char EOS = '\0', *EOM = &EOS; mqd_t id = 0; char file[] = "/mq", msg[N]; struct mq_attr attr = { 0, 1, 1, 0}; // {flags, maxmsg, msgsize, curmsgs} if (check(fork())) // parent/reader { id = check(mq_open(file, O_CREAT | O_RDONLY, 0600, &attr)); std::cout << "parent/reader: "; do { check(mq_receive(id, msg, N, NULL)); std::cout << msg[0]; } while (msg[0] != EOS); // ¿fin de mensaje? wait(nullptr); } else // child/writer { id = check(mq_open(file, O_CREAT | O_WRONLY, 0600, &attr)); std::cout << " child/writer: "; for (char c = 'a'; c <= 'z'; ++c) { check(mq_send(id, &c, 1, 0)); std::cout << c; } check(mq_send(id, EOM, 1, 0)); // fin de mensaje } std::cout << std::endl; mq_close(id); } //---------------------------------------------------------