Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://itpm.msu.su/LDP/lpg-0.4/node30.html
Дата изменения: Sun Apr 18 13:36:58 1999 Дата индексирования: Mon Oct 1 21:10:33 2012 Кодировка: |
The first structure we'll visit is the msgbuf structure. This particular data structure can be thought of as a template for message data. While it is up to the programmer to define structures of this type, it is imperative that you understand that there is actually a structure of type msgbuf. It is declared in linux/msg.h as follows:
/* message buffer for msgsnd and msgrcv calls */ struct msgbuf { long mtype; /* type of message */ char mtext[1]; /* message text */ };
The message type, represented in a positive number. This must be a positive number!
The message data itself.
The ability to assign a given message a type, essentially gives you the capability to multiplex messages on a single queue. For instance, client processes could be assigned a magic number, which could be used as the message type for messages sent from a server process. The server itself could use some other number, which clients could use to send messages to it. In another scenario, an application could mark error messages as having a message type of 1, request messages could be type 2, etc. The possibilities are endless.
On another note, do not be misled by the almost too-descriptive name assigned to the message data element (mtext). This field is not restricted to holding only arrays of characters, but any data, in any form. The field itself is actually completely arbitrary, since this structure gets redefined by the application programmer. Consider this redefinition:
struct my_msgbuf { long mtype; /* Message type */ long request_id; /* Request identifier */ struct client info; /* Client information structure */ };
There does exist an internal limit, however, of the maximum size of a given message. In Linux, this is defined in linux/msg.h as follows:
#define MSGMAX 4056 /* <= 4056 */ /* max size of message (bytes) */