Logo Search packages:      
Sourcecode: qchat version File versions  Download package

void LargeDatagram::initDatagram ( const char *  dtgrm,
quint32  dtgrm_len 
)

!!

Definition at line 55 of file largedatagram.cpp.

References m_lastFragmentNum, m_requestTimer, and m_selfDestroyTimer.

{
  quint8 cnl; // comp_name_len
  quint8 unl; // user_name_len

  if(m_inited || dtgrm_len < 69)
    return;

  m_programVersion    = str2US (dtgrm + 18);
  m_protocolVersion   = str2US (dtgrm + 20);
  m_destIP            = str2ULL(dtgrm + 22);
  m_packetType        =       *(dtgrm + 38);
  m_fragmentSize      = str2US (dtgrm + 41);//!!!
  m_firstFragmentTime = str2ULL(dtgrm + 47);
  m_channelID         = str2UL (dtgrm + 55);
  cnl                 =       *(dtgrm + 59);
  unl                 =       *(dtgrm + 60);

  if(dtgrm_len < quint32(69 + unl + cnl))
    return;

  m_totalFragments    = str2UL (dtgrm + 61);
  m_totalSize         = str2UL (dtgrm + 65);
  m_senderCompName    = QString().fromUtf8(dtgrm + 69      , cnl);
  m_senderName        = QString().fromUtf8(dtgrm + 69 + cnl, unl);

  // не m_totalFragments-1, потому что 0-й фрагмент является инициализирующим
  m_lastFragmentNum   = m_totalFragments;

  // вычисляем есть ли остаток
  if(m_totalSize < m_fragmentSize * m_totalFragments)
    m_lastFragmentSize  = m_totalSize - (m_fragmentSize * (m_totalFragments - 1));
  else
    m_lastFragmentSize  = m_fragmentSize;

  m_currentSize     = 0;
  m_fragmentsRemain = m_totalFragments;
  m_fragments       = (char*)calloc(m_totalFragments, 1);
  assert(NULL != m_fragments);

  //******************
  if((quint8)*(dtgrm + 38) == (quint8)Globals::FILE)
  {
    QByteArray ba;
    quint16    size;
    if(dtgrm_len >= quint32(69 + unl + cnl + 2))
    {
      size = str2US(dtgrm + 69 + unl + cnl);

      if(dtgrm_len >= quint32(69 + unl + cnl + 2 + size))
      {
        m_filename = QString().fromUtf8(dtgrm + 69 + unl + cnl + 2, size);
        qDebug("[LargeDatagram::initDatagram]: filename = %s", m_filename.toLocal8Bit().data());
      }

      m_isFile = true;
    }
    else
    {
      m_selfDestroyTimer->setInterval(m_selfDestroyInterval);
      m_selfDestroyTimer->start();
      return;
    }
  }
  //******************
  else
  {
    m_data = (char*)calloc(m_totalSize, 1);
    assert(NULL != m_data);
  }

  m_inited = true;

  if((!m_isFile || m_fileInited) && m_requestTimer && m_selfDestroyTimer)
  {
    m_requestTimer->setInterval(m_requestInterval);
    m_requestTimer->start();
    m_selfDestroyTimer->setInterval(m_selfDestroyInterval);
    m_selfDestroyTimer->start();
  }
  else if(!m_requestTimer || !m_selfDestroyTimer)
  {
    Globals::addError("Timer(s) is(are) NULL!");
    qWarning("[LargeDatagram[%d]::initDatagram]: Timer(s) is(are) NULL! req_timer = %p, destr_timer = %p\n ", m_datagramID, m_requestTimer, m_selfDestroyTimer);
  }
}


Generated by  Doxygen 1.6.0   Back to index