Applying Message Queues

A client and server program that uses message queues is presented here. The client issues the request, and the server receives the message and responds. The server simply performs a stat(2) or lstat(2) call, and returns the results to the client by a message.

The client and server programs both use a C++ object that has been created to make using message queues a little friendlier. The C++ object and its implementation will be presented first.

Listing 23.1 shows the file msq.h, which defines the C++ class Msq.

Code Listing 23.1. msq.h—The Msq Class Definition File
 1: // msq.h : 2: // 3: // Message Queue Class : 4: 5: #include <sys/types.h> 6: #include <sys/ipc.h> 7: #include <sys/msg.h> 8: 9: struct Msg { 10: long msgtyp; ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.