-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprintServer.c
35 lines (28 loc) · 849 Bytes
/
printServer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "serverMsg.h"
int main (){
char buffer[BUFFER_SIZE];
int printerQueue, replyQueue, requestQueue, n;
Message msg;
key_t printerTok = ftok(".", PRINTER);
key_t requestTok = ftok(".", REQUEST);
key_t replyTok = ftok(".", REPLY);
if ((printerQueue = msgget(printerTok, IPC_CREAT | 0660)) == -1){
perror("Queue creation failed");
return 1;
}
if ((requestQueue = msgget(requestTok, IPC_CREAT | 0660)) == -1){
perror("Queue creation failed");
return 1;
}
if ((replyQueue = msgget(replyTok, IPC_CREAT | 0660)) == -1){
perror("Queue creation failed");
return 1;
}
printf("Printing server is up! Queue: %d\n", printerQueue);
int msgSize = sizeof(Message) - sizeof(long int);
while(1){
n = msgrcv(printerQueue, &msg, msgSize, SERVER, 0);
printf("%s", msg.buffer);
}
return 1;
}