[ace-users] Clarification about C++Npv1 example about
mb_aligned message block, thanks!
Douglas C. Schmidt
schmidt at dre.vanderbilt.edu
Mon Sep 3 10:08:21 CDT 2007
Hi,
>In Chap 4.4, Logging_Handler::recv_log_record, line 27:
>27 payload->size (length + 8);
>
>Here I think it should be:
>27 payload->size(length + 8 +ACE_CDR::MAX_ALIGNMENT);
>
> >Because on line 12, it calls ACE_CDR::mb_align (payload); which may
> >cause wr_ptr_
> >is 8 before writing something to it.
> >
> >Thanks!
As per input from Steve Huston, this code changed quite some time back -
it's correct in the 3rd printing, July 2004:
1 int Logging_Handler::recv_log_record (ACE_Message_Block *&mblk)
2 {
3 ACE_INET_Addr peer_addr;
4 logging_peer_.get_remote_addr (peer_addr);
5 mblk = new ACE_Message_Block (MAXHOSTNAMELEN + 1);
6 peer_addr.get_host_name (mblk->wr_ptr (), MAXHOSTNAMELEN);
7 mblk->wr_ptr (strlen (mblk->wr_ptr ()) + 1); // Go past name.
8
9 ACE_Message_Block *payload =
10 new ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE);
11 // Align Message Block for a CDR stream.
12 ACE_CDR::mb_align (payload);
13
14 if (logging_peer_.recv_n (payload->wr_ptr (), 8) == 8) {
15 payload->wr_ptr (8); // Reflect addition of 8 bytes.
16
17 ACE_InputCDR cdr (payload);
18
19 ACE_CDR::Boolean byte_order;
20 // Use helper method to disambiguate booleans from chars.
21 cdr >> ACE_InputCDR::to_boolean (byte_order);
22 cdr.reset_byte_order (byte_order);
23
24 ACE_CDR::ULong length;
25 cdr >> length;
26
27 ACE_CDR::grow
28 (payload, 8 + ACE_CDR::MAX_ALIGNMENT + length);
29 if (logging_peer_.recv_n (payload->wr_ptr(), length) > 0) {
30 payload->wr_ptr (length); // Reflect additional bytes.
31 mblk->cont (payload);
32 return length; // Return length of the log record.
33 }
34 }
35 payload->release ();
36 mblk->release ();
37 payload = mblk = 0;
38 return -1;
39 }
Please see
http://www.cs.wustl.edu/~schmidt/ACE/book1/Errata.txt
for all the errata in C++NPv1.
Thanks,
Doug
More information about the Ace-users
mailing list