The Linux Programming Interface: a linux and unix system Programming Handbook



tải về 6.93 Mb.
Chế độ xem pdf
trang803/806
Chuyển đổi dữ liệu08.07.2022
Kích6.93 Mb.
#52607
1   ...   798   799   800   801   802   803   804   805   806
The Linux Programming Interface

953
Listing 46-6: Displaying all System V message queues on the system
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––
svmsg/svmsg_ls.c
#define _GNU_SOURCE
#include 
#include 
#include "tlpi_hdr.h"
int
main(int argc, char *argv[])
{
int maxind, ind, msqid;
struct msqid_ds ds;
struct msginfo msginfo;
/* Obtain size of kernel 'entries' array */
maxind = msgctl(0, MSG_INFO, (struct msqid_ds *) &msginfo);
if (maxind == -1)
errExit("msgctl-MSG_INFO");
printf("maxind: %d\n\n", maxind);
printf("index id key messages\n");
/* Retrieve and display information from each element of 'entries' array */
for (ind = 0; ind <= maxind; ind++) {
msqid = msgctl(ind, MSG_STAT, &ds);
if (msqid == -1) {
if (errno != EINVAL && errno != EACCES)
errMsg("msgctl-MSG_STAT"); /* Unexpected error */
continue; /* Ignore this item */
}
printf("%4d %8d 0x%08lx %7ld\n", ind, msqid,
(unsigned long) ds.msg_perm.__key, (long) ds.msg_qnum);
}
exit(EXIT_SUCCESS);
}
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––
svmsg/svmsg_ls.c
46.7
Client-Server Programming with Message Queues
In this section, we consider two of various possible designs for client-server applica-
tions using System V message queues:
z
The use of a single message queue for exchanging messages in both directions
between server and client.
z
The use of separate message queues for the server and for each client. The
server’s queue is used to receive incoming client requests, and responses are
sent to clients via the individual client queues.


954
Chapter 46
Which approach we choose depends on the requirements of our application. We
next consider some of the factors that may influence our choice.

tải về 6.93 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   798   799   800   801   802   803   804   805   806




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương