aboutsummaryrefslogtreecommitdiff
path: root/aufgabe3
diff options
context:
space:
mode:
authorThorsten Töpper <atsutane@freethoughts.de>2011-01-03 01:14:20 +0100
committerThorsten Töpper <atsutane@freethoughts.de>2011-01-03 01:14:20 +0100
commita0685b1f6b90b29d37f6f45c2279a837ae9ccd63 (patch)
treecc23d7f9a78359fbb4a5d42873d0dab235b94f57 /aufgabe3
parenta3bf1b9401cf596bf7bcb290e7c085c8e5e43cce (diff)
downloadprozesskommunikation-a0685b1f6b90b29d37f6f45c2279a837ae9ccd63.tar.gz
prozesskommunikation-a0685b1f6b90b29d37f6f45c2279a837ae9ccd63.tar.bz2
Aufgabe 3: conv.c Speicherfehler beseitigt, Code lesbarer gestaltet.
Diffstat (limited to 'aufgabe3')
-rw-r--r--aufgabe3/conv.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/aufgabe3/conv.c b/aufgabe3/conv.c
index 9ca90f8..6f4890c 100644
--- a/aufgabe3/conv.c
+++ b/aufgabe3/conv.c
@@ -9,12 +9,13 @@
#include "queue.h"
+char *message;
+
void conv() {
int random_number = 0;
mqd_t log;
mqd_t statistic;
- size_t message_size = sizeof(int)*2+1;
- char *msg_one, *msg_two;
+
/*
* Message Queues zur Kommunikation mit dem log
@@ -27,24 +28,25 @@ void conv() {
exit(EXIT_FAILURE);
}
+ /*
+ * Speicher für Nachricht allokieren.
+ */
+ if ((message = calloc(1, MQ_MSG_SIZE_SEND)) == NULL) {
+ perror("conv()");
+ exit(EXIT_FAILURE);
+ }
+
for (;;) {
random_number = rand();
- msg_one = calloc(1, message_size);
- msg_two = calloc(1, message_size);
-
- /* Message im Hexadezimalformat generieren. */
- sprintf(msg_one, "%x", random_number);
- sprintf(msg_two, "%x", random_number);
-
- printf("conv:\t%s\t\t%s\n", msg_one, msg_two);
-// fgetc(stdin);
+ /* Zufallszahl ins Hexadezimalformat konvertieren. */
+ sprintf(message, "%x", random_number);
- /* Message sowohl in die Queue zum log Prozess als auch
+ /* Nachricht sowohl in die Queue zum log Prozess als auch
* in die Queue zum statistic Prozess schreiben.
*/
- if ((mq_send(log, msg_one, strlen(msg_one)+1, 0) == -1) ||
- mq_send(statistic, msg_two, strlen(msg_two)+1, 0) == -1){
+ if ((mq_send(log, message, MQ_MSG_SIZE_SEND, 0) == -1) ||
+ mq_send(statistic, message, MQ_MSG_SIZE_SEND, 0) == -1){
perror("conv() mq_send");
exit(EXIT_FAILURE);
}
@@ -54,6 +56,7 @@ void conv() {
void conv_cleanup() {
printf("conv cleanup\n");
+ free(message);
mq_unlink(MQ_TO_LOG);
mq_unlink(MQ_TO_STATISTIC);
_exit(EXIT_SUCCESS);