2 // author : Boris Kolpackov <boris@kolpackov.net>
3 #include "ace/Vector_T.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_NS_string.h"
7 #include "ace/RMCast/Socket.h"
12 ACE_Vector
<unsigned char, ACE_VECTOR_DEFAULT_SIZE
>
18 ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
22 if (argc
< 2) throw args ();
24 ACE_INET_Addr
addr (argv
[1]);
26 //FUZZ: disable check_for_lack_ACE_OS
27 // Turn on message loss and reordering simulation.
29 ACE_RMCast::Socket
socket (addr
, false, true);
30 //FUZZ: enable check_for_lack_ACE_OS
36 // VC6 does not know about the new rules.
39 for (unsigned short i
= 0; i
< payload_size
; i
++)
41 expected_msg
.payload
[i
] = i
;
45 Status_List
received (message_count
);
46 Status_List
damaged (message_count
);
47 Status_List
duplicate (message_count
);
49 // VC6 does not know about new rules.
52 for (unsigned long i
= 0; i
< message_count
; ++i
)
54 received
.push_back (0);
55 damaged
.push_back (0);
56 duplicate
.push_back (0);
65 ssize_t s
= socket
.size ();
67 if (s
== -1 && errno
== ENOENT
)
69 ACE_ERROR ((LM_ERROR
, "unavailable message detected\n"));
73 socket
.recv (&msg
, sizeof (msg
));
78 if (s
!= (ssize_t
)sizeof (msg
))
80 ACE_ERROR ((LM_ERROR
, "unexpected message size %d, expected %d\n",
85 if (socket
.recv (&msg
, sizeof (msg
)) != s
)
88 "recv() reported different size than size()\n"));
92 if (received
[msg
.sn
] == 1)
94 duplicate
[msg
.sn
] = 1;
100 if (ACE_OS::memcmp (expected_msg
.payload
,
102 payload_size
* sizeof(short)) != 0)
108 if (msg
.sn
+ 1 == message_count
) break;
111 unsigned long lost_count (0), damaged_count (0), duplicate_count (0);
114 for (Status_List::Iterator
i (received
); !i
.done (); i
.advance ())
119 if (*e
== 0) ++lost_count
;
125 for (Status_List::Iterator
i (damaged
); !i
.done (); i
.advance ())
130 if (*e
== 1) ++damaged_count
;
136 for (Status_List::Iterator
i (duplicate
); !i
.done (); i
.advance ())
141 if (*e
== 1) ++duplicate_count
;
145 ACE_DEBUG ((LM_DEBUG
,
153 if (damaged_count
!= 0 || duplicate_count
!= 0)
158 // It is ok to lose some number of messages at the beginning.
160 unsigned long count (0);
162 for (Status_List::Iterator
i (received
); !i
.done (); i
.advance ())
170 break; // Seen first ok message.
173 if (lost_count
!= count
)
181 ACE_ERROR ((LM_ERROR
,
182 "usage: %s <IPv4 multicast address>:<port>\n", argv
[0]));