debugging the protocol

Havoc Pennington hp at
Thu Jun 14 16:35:46 PDT 2007


Simon Burton wrote:
> One thing I am curious about. The actual message body is not
> null padded. This means when we get multiple messages from one
> network read, we may get mis-aligned messages. In my code I detect
> this situation and just copy the message to an 8-byte aligned
> location. Wouldn't it make more sense to pad each message so
> we don't have this problem ?

Probably, but it's too late to change due to back compat issues.

You can perhaps avoid the copies if you are willing to make your life 
complicated, because the message header has the message length in the 
initial fixed-length portion of the header. The length of the body is a 
UINT32, and the length of the header itself is at the start of the array 
of header fields (arrays include their length in bytes).

So, the series of reads would be:

  read_initial_part_of_header() -> store length
  read (remaining length of current message)
  read_initial_part_of_header() -> store length
  read (remaining length of current message)

and so forth. To avoid two reads per message, you might be able to do 
something with readv() to read the known message length into one buffer 
and the next header into a second buffer in a single syscall.

I would certainly start by doing something simpler though until you 
learn that this is truly a performance issue in your app.


More information about the dbus mailing list