Commit cd9922b0 authored by Pavel Vainerman's avatar Pavel Vainerman

(UNet2): Исправил ошибку в формировании пакета. Массив выделенный для

хранения битовых данных, был больше чем нужно.
parent a6b8eecd
......@@ -92,8 +92,8 @@ bool UDPMessage::setDData( size_t index, bool val )
if( index >= MaxDCount )
return false;
size_t nbyte = index / sizeof(unsigned char);
size_t nbit = index % sizeof(unsigned char);
size_t nbyte = index / 8*sizeof(unsigned char);
size_t nbit = index % 8*sizeof(unsigned char);
// выставляем бит
unsigned char d = d_dat[nbyte];
......@@ -119,8 +119,8 @@ bool UDPMessage::dValue( size_t index )
if( index >= MaxDCount )
return UniSetTypes::DefaultObjectId;
size_t nbyte = index / sizeof(unsigned char);
size_t nbit = index % sizeof(unsigned char);
size_t nbyte = index / 8*sizeof(unsigned char);
size_t nbit = index % 8*sizeof(unsigned char);
return ( d_dat[nbyte] & (1<<nbit) );
}
......@@ -144,8 +144,8 @@ size_t UDPMessage::transport_msg( UDPPacket& p )
i += sz;
// копируем булевые данные
size_t nbyte = dcount / sizeof(unsigned char);
size_t nbit = dcount % sizeof(unsigned char);
size_t nbyte = dcount / 8*sizeof(unsigned char);
size_t nbit = dcount % 8*sizeof(unsigned char);
sz = nbit > 0 ? nbyte + 1 : nbyte;
memcpy(&(p.data[i]),d_dat,sz);
i += sz;
......@@ -184,8 +184,8 @@ size_t UDPMessage::getMessage( UDPMessage& m, UDPPacket& p )
i += sz;
// копируем булевые данные
size_t nbyte = m.dcount / sizeof(unsigned char);
size_t nbit = m.dcount % sizeof(unsigned char);
size_t nbyte = m.dcount / 8*sizeof(unsigned char);
size_t nbit = m.dcount % 8*sizeof(unsigned char);
sz = nbit > 0 ? nbyte + 1 : nbyte;
if( sz > sizeof(m.d_dat) )
......
......@@ -41,9 +41,11 @@ namespace UniSetUDP
friend std::ostream& operator<<( std::ostream& os, UDPAData& p );
}__attribute__((packed));
static const size_t MaxACount = 600;
static const size_t MaxDCount = 600;
static const size_t MaxDDataCount = MaxDCount / sizeof(unsigned char);
// Хотелось бы не вылезать за общий размер посылаемых пакетов 8192. (550,900 --> 8133)
static const size_t MaxACount = 550;
static const size_t MaxDCount = 900;
static const size_t MaxDDataCount = 1 + MaxDCount / 8*sizeof(unsigned char);
struct UDPPacket
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment