Пример #1
0
int64_t CUDT::recvfile(UDTSOCKET u, fstream& ofs, const int64_t& offset, const int64_t& size, const int& block)
{
   try
   {
      CUDT* udt = s_UDTUnited.lookup(u);
      return udt->recvfile(ofs, offset, size, block);
   }
   catch (CUDTException e)
   {
      s_UDTUnited.setError(new CUDTException(e));
      return ERROR;
   }
   catch (...)
   {
      s_UDTUnited.setError(new CUDTException(-1, 0, 0));
      return ERROR;
   }
}
Пример #2
0
void recethread::run()
{  
    if (m_iFolder == 0)
    {
        //udt = new CUDT();
        //connect(udt,SIGNAL(sendProgress(qint64,qint64)),this,SLOT(onSendProgress(qint64,qint64)));

       // get size information

        int iContent = 3;
        char content[iContent+1];
        if (UDT::ERROR == UDT::recv(m_handle, content, iContent, 0))
        {
           qDebug() << "recv: " << UDT::getlasterror().getErrorMessage() << endl;
           return ;
        }
        else
        {
              qDebug()<< "receive file or directory request success";
             content[iContent] = '\0';

            char *strContent = new char[iContent+1];
            memset(strContent,0,iContent+1);
            memcpy(strContent, content, iContent);

            if (0 == strcmp(strContent, "FCS"))
            {
                qDebug() << "receive FCS";
            }
            else
            {
                return;
            }

        }


         if (UDT::ERROR == UDT::recv(m_handle, (char*)&size, sizeof(uint64_t), 0))
         {
             qDebug() << "handle: " << m_handle;
             qDebug() << "send: " << UDT::getlasterror().getErrorMessage() << endl;
             //qDebug() << "receive file size success";
             return;
         }

         if (size < 0)
         {
            return;
         }

         qDebug() << "receive file size : " << size;


        std::fstream ofs(m_strFileName.toStdString().c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
        int64_t recvsize;
        int64_t offset = 0;

        CUDT *udt = CUDT::getUdt(m_handle);
        udt->setFolderSize(size);
        connect(udt,SIGNAL(sendProgress(qint64,double)),this,SLOT(onSendProgress(qint64,double)));

        if (UDT::ERROR == (recvsize = udt->recvfile(ofs, offset, size)))
        {
            QString str = UDT::getlasterror().getErrorMessage();
            //cout << "recvfile: " << UDT::getlasterror().getErrorMessage() << endl;
            //return -1;
        }

        emit sendSuccess();

        UDT::close(m_handle);

        ofs.close();
    }