From 455924c2b4eff513609d6bcf8fc6f247fbd8623a Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Wed, 28 Oct 2020 12:56:59 -0500 Subject: Project now runs and does not hang forever Still doesn't work though --- P2/lib/utils.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'P2') diff --git a/P2/lib/utils.c b/P2/lib/utils.c index 9693268..f485b11 100644 --- a/P2/lib/utils.c +++ b/P2/lib/utils.c @@ -11,6 +11,7 @@ int openQueue() { } char *getChunkData(int mapperID) { + printf("GETTING CHUNK DATA\n"); //Message struct msgBuffer message; //Queue ID @@ -20,6 +21,7 @@ char *getChunkData(int mapperID) { if (strncmp("END", message.msgText, 3)) { struct msgBuffer ACK = {mapperID, "ACK"}; msgsnd(mid, &ACK, MSGSIZE, 0); + return NULL; } char* value = message.msgText; return value; @@ -27,22 +29,26 @@ char *getChunkData(int mapperID) { // sends chunks of size 1024 to the mappers in RR fashion void sendChunkData(char *inputFile, int nMappers) { + printf("SENDING CHUNK DATA\n"); struct msgBuffer message; // open message queue int msgid = openQueue(); + int map = 1; // message.msgText = 1; int fd = open(inputFile, O_RDONLY); // construct chunks of 1024 bytes - char* buf[chunkSize]; - memset(buf, '\0', chunkSize); - while(read(fd, buf, chunkSize) != 0) { - printf("%s\n", buf); + memset(message.msgText, '\0', MSGSIZE); + while(read(fd, message.msgText, chunkSize) != 0) { + printf("%s\n", message.msgText); /* Go to the end of the chunk, check if final character is a space if character is a space, do nothing else cut off before that word and put back file */ // TODO! help - - msgsnd(msgid, &message, 1, 0); + message.msgType = map++; + //THIS IS DEBUG, NOT ACTUALLY FUNCTIONAL + msgsnd(msgid, &message, map, 0); + if (map > nMappers) + map = 1; } for (int i = 1; i < nMappers; i++) { -- cgit v1.2.3