catch (IOException se)
{
throw to_COMM_FAILURE (se);
}
// the packet was received successfully.
CDRInputStream in = new CDRInputStream (configuration.getORB (), packet.getData ());
// Read the header
//
// Manually read in the stream rather than using the generated
// PacketHeader_1_0Helper
// as we may need to alter endian half way through.
org.omg.MIOP.PacketHeader_1_0 header = new org.omg.MIOP.PacketHeader_1_0 ();
header.magic = new char[4];
in.read_char_array (header.magic, 0, 4);
// Verify the message is MIOP
if ( ! MulticastUtil.matchMIOPMagic (header.magic))
{
// if it isn't a MIOP message I can ignore it
continue;
}
// We know it is MIOP from now on.
header.hdr_version = in.read_octet ();
header.flags = in.read_octet ();
// Set endian for the stream
in.setLittleEndian ((0x01 & header.flags) != 0);
header.packet_length = in.read_ushort ();
header.packet_number = in.read_ulong ();
header.number_of_packets = in.read_ulong ();
header.Id = org.omg.MIOP.UniqueIdHelper.read (in);
int pos = in.get_pos ();
// difference to next MulticastUtil.BOUNDARY (which is an 8 byte boundary)
int header_padding = MulticastUtil.BOUNDARY - (pos % MulticastUtil.BOUNDARY);
header_padding = (header_padding == MulticastUtil.BOUNDARY) ? 0 : header_padding;
// skip header_padding bytes anyway, because if no body is
// present, nobody will try to read it
in.skip (header_padding);
// read the GIOP data
byte data[] = new byte[header.packet_length];
if (in.available () < data.length)
{
throw new MARSHAL
(
"Impossible length in MIOP header. Header denotes length of " +
header.packet_length +
" but only " +
in.available () +
" is available."
);
}
in.read_octet_array (data, 0, header.packet_length);
String messageId = new String (header.Id);
FragmentedMessage message = incompleteMessages.get (messageId);
// verify if it's the first message to arrive