void _chibi_assert_not_null(chibi_testcase *tc, void *ptr, const char *msg, const char *srcfile, int line) { if (ptr == NULL) { tc->error_msg = assemble_message(msg, srcfile, tc->fname, line); tc->success = 0; _exit_on_fail(tc); } }
int main(int argc, char **argv) { if (argc != 2) { printf("Usage: packet_sender <num of messages to receive>\n"); exit(-1); } int k = atoi(argv[1]); /* num of messages you will get from the sender */ int i; char *msg; mm_t mm2; mm = mm2; mm_init(&mm, 10, MSGSIZE); message.num_packets = 0; pid_queue_msg pqm; pqm.pid = getpid(); pqm.mtype = QUEUE_MSG_TYPE; msqid = msgget(key, 0666|IPC_CREAT); printf("mid: %d\n", msqid); msgsnd(msqid, &pqm, sizeof(int), 0); printf("Sent pid\n"); printf("pid = %d\n", pqm.pid); /* set up SIGIO handler to readhow many: 6 GOT IT: message=aaabbbcccdddeeeff incoming packets from the queue. Check packet_handler() */ struct sigaction act; act.sa_sigaction = (void *)packet_handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaction(SIGIO, &act, NULL); for (i = 1; i <= k; i++) { packet_t pkt; while (pkt_cnt < pkt_total) { pause(); /* block until next packet */ } msg = assemble_message(); if (msg == NULL) { perror("Failed to assemble message"); } else { fprintf(stderr, "GOT IT: message=%s\n", msg); free(msg); } } // deallocate memory manager mm_release(&mm); // remove the queue once done msgctl(msqid, IPC_RMID, NULL); return EXIT_SUCCESS; }
void _chibi_fail(chibi_testcase *tc, const char *msg, const char *srcfile, int line) { tc->error_msg = assemble_message(msg, srcfile, tc->fname, line); tc->success = 0; _exit_on_fail(tc); }