@@ -16,22 +16,16 @@ namespace Mercury
1616Bundle::Bundle (Channel * pChannel, PacketType pt):
1717 pChannel_ (pChannel),
1818 pCurrPacket_ (NULL ),
19+ currMsgID_ (0 ),
20+ currMsgPacketCount_ (0 ),
21+ currMsgLength_ (0 ),
22+ currMsgHandlerLength_ (0 ),
1923 packets_ (),
2024 isTCPPacket_ (pt == TCP_PACKET )
2125{
2226 newPacket ();
2327}
2428
25- // -------------------------------------------------------------------------------------
26- Bundle::Bundle (Packet * p, PacketType pt):
27- pChannel_ (NULL ),
28- pCurrPacket_ (NULL ),
29- packets_ (),
30- isTCPPacket_ (pt == TCP_PACKET )
31- {
32- pCurrPacket_ = p;
33- }
34-
3529// -------------------------------------------------------------------------------------
3630Bundle::~Bundle ()
3731{
@@ -53,8 +47,17 @@ Packet* Bundle::newPacket()
5347// -------------------------------------------------------------------------------------
5448void Bundle::finish (void )
5549{
50+ currMsgLength_ += pCurrPacket_->size ();
5651 packets_.push_back (pCurrPacket_);
52+
53+ // 此处对于非固定长度的消息来说需要设置它的最终长度信息
54+ if (currMsgHandlerLength_ == 0 )
55+ packets_[packets_.size () - currMsgPacketCount_]->setPacketLength (currMsgLength_);
56+
5757 pCurrPacket_ = NULL ;
58+ currMsgID_ = 0 ;
59+ currMsgPacketCount_ = 0 ;
60+ currMsgLength_ = 0 ;
5861}
5962
6063// -------------------------------------------------------------------------------------
@@ -66,6 +69,9 @@ void Bundle::clear()
6669
6770 packets_.clear ();
6871 SAFE_RELEASE (pCurrPacket_);
72+
73+ currMsgID_ = 0 ;
74+ currMsgPacketCount_ = 0 ;
6975}
7076
7177// -------------------------------------------------------------------------------------
@@ -95,9 +101,13 @@ void Bundle::send(EndPoint& ep)
95101void Bundle::newMessage (const MessageHandler& msgHandler)
96102{
97103 KBE_ASSERT (pCurrPacket_ != NULL );
98-
99- (*pCurrPacket_) << msgHandler.msgID ;
104+
105+ pCurrPacket_->messageID (msgHandler.msgID );
106+
100107 numMessages_++;
108+ currMsgID_ = msgHandler.msgID ;
109+ currMsgPacketCount_ = 1 ;
110+ currMsgHandlerLength_ = msgHandler.msgLen ;
101111}
102112
103113// -------------------------------------------------------------------------------------
0 commit comments