Message structure and partial “server” code -using IPC mechanism message queue- seen below. a. Write needed code for creating message queue b. Write needed code for deleting message queue c. Write the corresponding partial “client” code for this partial server. Message Structure: typedef struct { long int msg_to; // Message in queue for this type long int msg_fm; // Placed in the queue by this type char buffer[BUFSIZ]; // The actual message }MESSAGE; Partial Server Code: 1. while (1) {
The Message structure and partial “server” code -using IPC
a. Write needed code for creating message queue
b. Write needed code for deleting message queue
c. Write the corresponding partial “client” code for this partial server.
Message Structure:
typedef struct {
long int msg_to; // Message in queue for this type
long int msg_fm; // Placed in the queue by this type
char buffer[BUFSIZ]; // The actual message
}MESSAGE;
Partial Server Code:
1. while (1) {
2. memset( msg.buffer, 0x0, BUFSIZ );
3. if ((n=msgrcv(mid, &msg, BUFSIZ, SERVER, 0)) == -1 ) {
4. perror("Server: msgrcv");
5. return 2;
6. } else if (n == 0) break;
7. process_msg(msg.buffer, strlen(msg.buffer));
8. msg.msg_to = msg.msg_fm;
9. msg.msg_fm = SERVER;
10. n += sizeof(msg.msg_fm);
11. if (msgsnd(mid, &msg, n, 0) == -1 ) {
12. perror("Server: msgsnd");
13. return 3;
14. }
15. }
Trending now
This is a popular solution!
Step by step
Solved in 2 steps