Message structures


Streams messages are chunks of data that are passed between queues. An individual message is composed of one or more message blocks, or pieces of data linked together. Each block consists of:

  • A struct msgb containing information about additional blocks, other messages, a pointer to the actual data in the message, and flags

  • A struct datab that contains pointers and sizes of the actual buffer with the data in it

  • The real data buffer, that can be of various fixed sizes

The reason for the separation between message blocks, data blocks, and data buffers, is that buffers may vary in size , and data blocks (and the associated buffers) can be shared by more than one message block. For example, if a chunk of data is received from a terminal and must be echoed back out, the actual data need not be duplicated into another buffer and sent downstream. It can simply be pointed to by a new message block in a completely different queue. Thus, a data block will contain a reference count, which says how many message block headers are pointing to it. It's not polite to remove the data block until the reference count goes down to zero.

These various structures that compose a "message" are declared in the stream.h header file. Solaris 2, again, defines more information than the original structure in SunOS 4.x, but the common pieces are the same:

Example 25-3 Message block structure as defined in /usr/include/sys/stream.h
 /*   * Message block descriptor   */  struct msgb {        struct  msgb    *b_next;         struct  msgb    *b_prev;         struct  msgb    *b_cont;         unsigned char   *b_rptr;         unsigned char   *b_wptr;         struct datab    *b_datap; 

And more data for the Solaris 2 version:

 unsigned char   b_band;         unsigned short  b_flag;         queue_t         *b_queue;       /* for sync queues */  }; 

The elements are:

  • A pointer to the next message in sequence on this queue, if any

  • A pointer to the previous message, if any

  • Another pointer to any continuation blocks needed to finish off this particular message

  • The actual location of the data (for reading)

  • The first free byte in the data buffer (for writing)

  • The pointer to the data block

Messages may be composed of multiple linked message blocks by using the b_cont pointer. Each message block has in it the address of the data, so that reading, modifying, or writing can be done quickly. The data is not null terminated , if you are looking at tty character input or output. The write pointer indicates the end of the data; if you want to examine it, you must dump out data up to but not including that byte. You'll have to subtract the pointers to find out how much there is.



PANIC. UNIX System Crash Dump Analysis Handbook
PANIC! UNIX System Crash Dump Analysis Handbook (Bk/CD-ROM)
ISBN: 0131493868
EAN: 2147483647
Year: 1994
Pages: 289
Authors: Chris Drake

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net