aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/dcc
diff options
context:
space:
mode:
authorGravatar Fabio Bas2009-10-04 22:05:54 +0000
committerGravatar Fabio Bas2009-10-04 22:05:54 +0000
commitee652dfa69addcadc8a27b94d3f2db391379a0a7 (patch)
tree35dbf1fa7c8beea8ddd55cd5a1f21a0aebbfca6a /src/modules/dcc
parentfix for #589 (diff)
downloadKVIrc-ee652dfa69addcadc8a27b94d3f2db391379a0a7.tar.gz
KVIrc-ee652dfa69addcadc8a27b94d3f2db391379a0a7.tar.bz2
KVIrc-ee652dfa69addcadc8a27b94d3f2db391379a0a7.zip
fix for #563
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@3538 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/dcc')
-rw-r--r--src/modules/dcc/broker.cpp4
-rw-r--r--src/modules/dcc/broker.h10
-rw-r--r--src/modules/dcc/descriptor.h28
-rw-r--r--src/modules/dcc/requests.cpp2
-rw-r--r--src/modules/dcc/send.cpp208
-rw-r--r--src/modules/dcc/send.h48
6 files changed, 157 insertions, 143 deletions
diff --git a/src/modules/dcc/broker.cpp b/src/modules/dcc/broker.cpp
index cd4a49ba1..4d0453aa8 100644
--- a/src/modules/dcc/broker.cpp
+++ b/src/modules/dcc/broker.cpp
@@ -820,7 +820,7 @@ void KviDccBroker::sendFileExecute(KviDccBox * box,KviDccDescriptor *dcc)
delete dcc;
return;
}
-
+
dcc->szFileName = dcc->szLocalFileName;
dcc->szFileName = QFileInfo(dcc->szFileName).fileName();
@@ -849,7 +849,7 @@ bool KviDccBroker::handleResumeAccepted(const char * filename,const char * port,
return KviDccFileTransfer::handleResumeAccepted(filename,port,szZeroPortTag);
}
-bool KviDccBroker::handleResumeRequest(KviDccRequest * dcc,const char * filename,const char * port,unsigned int filePos,const char * szZeroPortTag)
+bool KviDccBroker::handleResumeRequest(KviDccRequest * dcc,const char * filename,const char * port,unsigned long filePos,const char * szZeroPortTag)
{
//debug("HANDLE %s %s %u %s",filename,port,filePos,szZeroPortTag);
// the zeroPOrtTag is nonempty here only if port == 0
diff --git a/src/modules/dcc/broker.h b/src/modules/dcc/broker.h
index 491fd1283..5be531571 100644
--- a/src/modules/dcc/broker.h
+++ b/src/modules/dcc/broker.h
@@ -46,10 +46,10 @@ class KviDccBox;
class KviDccZeroPortTag
{
public:
- QDateTime m_tTimestamp;
- QString m_szTag;
- unsigned int m_uFileSize; // outgoing file size, valid only for file transfers obviously
- unsigned int m_uResumePosition; // if 0 = no resume, valid only for file transfers obviously
+ QDateTime m_tTimestamp;
+ QString m_szTag;
+ unsigned long m_uFileSize; // outgoing file size, valid only for file transfers obviously
+ unsigned long m_uResumePosition; // if 0 = no resume, valid only for file transfers obviously
};
class KviDccBroker : public QObject
@@ -90,7 +90,7 @@ public:
void sendFileManage(KviDccDescriptor * dcc);
bool handleResumeAccepted(const char * filename,const char * port,const char * szZeroPortTag);
- bool handleResumeRequest(KviDccRequest * dcc,const char * filename,const char * port,unsigned int filePos,const char * szZeroPortTag);
+ bool handleResumeRequest(KviDccRequest * dcc,const char * filename,const char * port,unsigned long filePos,const char * szZeroPortTag);
public slots:
void rsendExecute(KviDccBox * box,KviDccDescriptor * dcc);
diff --git a/src/modules/dcc/descriptor.h b/src/modules/dcc/descriptor.h
index ac4eadb22..d1ec565f2 100644
--- a/src/modules/dcc/descriptor.h
+++ b/src/modules/dcc/descriptor.h
@@ -78,7 +78,7 @@ public:
// Generic parameters
QString szType; // DCC protocol : CHAT , SCHAT , SEND , TSSEND....
- bool bActive; // active or passive connection ?
+ bool bActive; // active or passive connection ?
QString szNick; // remote user nickname
QString szUser; // remote user name (unknown for passive dcc)
@@ -94,21 +94,21 @@ public:
QString szListenIp; // passive only : ip to listen on
QString szListenPort; // passive only : port to listen on
- bool bSendRequest; // passive only : true if we have to send the CTCP request
+ bool bSendRequest; // passive only : true if we have to send the CTCP request
QString szFakeIp; // passive only : fake ip to send in the CTCP
QString szFakePort; // passive only : fake port to send in the CTCP
- bool bDoTimeout; // the marshall has to setup a timeout ?
+ bool bDoTimeout; // the marshall has to setup a timeout ?
- bool bIsTdcc; // is this a TDCC ?
+ bool bIsTdcc; // is this a TDCC ?
- bool bOverrideMinimize; // Override the default minimize option ?
- bool bShowMinimized; // Show minimized ? (valid if bOverrideMinimize is true)
+ bool bOverrideMinimize; // Override the default minimize option ?
+ bool bShowMinimized; // Show minimized ? (valid if bOverrideMinimize is true)
- bool bAutoAccept; // Auto accepted dcc send/chat ?
+ bool bAutoAccept; // Auto accepted dcc send/chat ?
#ifdef COMPILE_SSL_SUPPORT
- bool bIsSSL; // do we have to use SSL ?
+ bool bIsSSL; // do we have to use SSL ?
#endif
// Specific parameters
@@ -120,15 +120,15 @@ public:
QString szLocalFileName; // RECVFILE: save file name selected, SENDFILE: file to send
QString szLocalFileSize; // RECVFILE: local file size (to resume), SENDFILE: file to send size
- bool bRecvFile; // do we have to RECEIVE the file or SEND it ?
- bool bResume; // do we want to resume ?
- bool bNoAcks; // blind dcc send ? (do not receive nor send acknowledges)
+ bool bRecvFile; // do we have to RECEIVE the file or SEND it ?
+ bool bResume; // do we want to resume ?
+ bool bNoAcks; // blind dcc send ? (do not receive nor send acknowledges)
- bool bIsIncomingAvatar; // It is an Incoming Avatar DCC SEND ?
+ bool bIsIncomingAvatar; // It is an Incoming Avatar DCC SEND ?
// DCC VOICE
- KviStr szCodec; // codec name
- int iSampleRate; // Sample rate
+ KviStr szCodec; // codec name
+ int iSampleRate; // Sample rate
public:
QString protocol(){ return szType; };
bool isActive(){ return bActive; };
diff --git a/src/modules/dcc/requests.cpp b/src/modules/dcc/requests.cpp
index 54876cf47..5078dea91 100644
--- a/src/modules/dcc/requests.cpp
+++ b/src/modules/dcc/requests.cpp
@@ -551,7 +551,7 @@ static void dccModuleParseDccResume(KviDccRequest *dcc)
// DCC SEND <filename> <remoteip> <remoteport> <filesize> <tag>
bool bOk;
- unsigned int filePos = dcc->szParam3.toUInt(&bOk);
+ quint64 filePos = dcc->szParam3.toULong(&bOk);
if(!bOk)
{
if(!dcc->ctcpMsg->msg->haltOutput())
diff --git a/src/modules/dcc/send.cpp b/src/modules/dcc/send.cpp
index baab4457f..5a3ba3029 100644
--- a/src/modules/dcc/send.cpp
+++ b/src/modules/dcc/send.cpp
@@ -97,12 +97,12 @@ KviDccRecvThread::KviDccRecvThread(QObject * par,kvi_socket_t fd,KviDccRecvThrea
: KviDccThread(par,fd)
{
m_pOpt = opt;
- m_iAverageSpeed = -1;
- m_iInstantSpeed = -1;
- m_iFilePosition = 0;
+ m_uAverageSpeed = 0;
+ m_uInstantSpeed = 0;
+ m_uFilePosition = 0;
- m_iTotalReceivedBytes = 0;
- m_iInstantReceivedBytes = 0;
+ m_uTotalReceivedBytes = 0;
+ m_uInstantReceivedBytes = 0;
m_pFile = 0;
m_pTimeInterval = new KviMSecTimeInterval();
m_uStartTime = 0;
@@ -118,7 +118,7 @@ KviDccRecvThread::~KviDccRecvThread()
bool KviDccRecvThread::sendAck(int filePos)
{
- int size = htonl(filePos);
+ quint32 size = htonl(filePos & 0xffffffff);
if(kvi_socket_send(m_fd,(void *)(&size),4) != 4)
{
postErrorEvent(KviError_acknowledgeError);
@@ -136,20 +136,20 @@ void KviDccRecvThread::updateStats()
unsigned long uElapsedTime = uCurTime - m_uStartTime;
if(uElapsedTime < 1)uElapsedTime = 1;
- m_iFilePosition = m_pFile->pos();
- m_iAverageSpeed = m_iTotalReceivedBytes / uElapsedTime;
+ m_uFilePosition = m_pFile->pos();
+ m_uAverageSpeed = m_uTotalReceivedBytes / uElapsedTime;
if(m_uInstantSpeedInterval > INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_MSECS)
{
unsigned int uMSecsOfTheNextInterval = 0;
if(m_uInstantSpeedInterval < (INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_MSECS + (INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_MSECS / 2)))
uMSecsOfTheNextInterval = m_uInstantSpeedInterval - INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_MSECS;
- m_iInstantSpeed = (m_iInstantReceivedBytes * 1000) / m_uInstantSpeedInterval;
- m_iInstantReceivedBytes = 0;
+ m_uInstantSpeed = (m_uInstantReceivedBytes * 1000) / m_uInstantSpeedInterval;
+ m_uInstantReceivedBytes = 0;
m_uInstantSpeedInterval = uMSecsOfTheNextInterval;
} else {
if(uElapsedTime <= INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_SECS)
- m_iInstantSpeed = m_iAverageSpeed;
+ m_uInstantSpeed = m_uAverageSpeed;
}
m_pMutex->unlock();
}
@@ -245,7 +245,7 @@ void KviDccRecvThread::run()
m_pMutex->lock(); // FIXME: how to remove this lock ?
unsigned int uMaxPossible = (m_pOpt->uMaxBandwidth < MAX_DCC_BANDWIDTH_LIMIT) ? m_pOpt->uMaxBandwidth * INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_SECS : MAX_DCC_BANDWIDTH_LIMIT * INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_SECS;
m_pMutex->unlock();
- unsigned int uToRead = uMaxPossible > ((unsigned int)(m_iInstantReceivedBytes)) ? uMaxPossible - m_iInstantReceivedBytes : 0;
+ unsigned int uToRead = uMaxPossible > m_uInstantReceivedBytes ? uMaxPossible - m_uInstantReceivedBytes : 0;
if(uToRead > KVI_DCC_RECV_BLOCK_SIZE)uToRead = KVI_DCC_RECV_BLOCK_SIZE;
if(uToRead > 0)
@@ -255,12 +255,12 @@ void KviDccRecvThread::run()
if(readLen > 0)
{
// Readed something useful...write back
- if((m_pOpt->iTotalFileSize > -1) && ((readLen + (int)m_pFile->pos()) > m_pOpt->iTotalFileSize))
+ if(((uint)(readLen + m_pFile->pos())) > m_pOpt->uTotalFileSize)
{
postMessageEvent(__tr_no_lookup_ctx("WARNING: The peer is sending garbage data past the end of the file","dcc"));
postMessageEvent(__tr_no_lookup_ctx("WARNING: Ignoring data past the declared end of file and closing the connection","dcc"));
- readLen = m_pOpt->iTotalFileSize - m_pFile->pos();
+ readLen = m_pOpt->uTotalFileSize - m_pFile->pos();
if(readLen > 0)
{
if(m_pFile->write(buffer,readLen) != readLen)
@@ -277,8 +277,8 @@ void KviDccRecvThread::run()
}
// Update stats
- m_iTotalReceivedBytes += readLen;
- m_iInstantReceivedBytes += readLen;
+ m_uTotalReceivedBytes += readLen;
+ m_uInstantReceivedBytes += readLen;
updateStats();
// Now send the ack
@@ -286,9 +286,9 @@ void KviDccRecvThread::run()
{
// No acks...
// Interrupt if the whole file has been received
- if(m_pOpt->iTotalFileSize > 0)
+ if(m_pOpt->uTotalFileSize > 0)
{
- if(((int)(m_pFile->pos())) == m_pOpt->iTotalFileSize)
+ if((quint64)m_pFile->pos() == m_pOpt->uTotalFileSize)
{
// Received the whole file...die
KviThreadEvent * e = new KviThreadEvent(KVI_DCC_THREAD_EVENT_SUCCESS);
@@ -322,8 +322,8 @@ void KviDccRecvThread::run()
if(readLen == 0)
{
- // readed EOF..
- if((((int)(m_pFile->pos())) == m_pOpt->iTotalFileSize) || (m_pOpt->iTotalFileSize < 0))
+ // read EOF..
+ if(((quint64)m_pFile->pos() == m_pOpt->uTotalFileSize) || (m_pOpt->uTotalFileSize == 0))
{
// success if we got the whole file or if we don't know the file size (we trust the peer)
KviThreadEvent * e = new KviThreadEvent(KVI_DCC_THREAD_EVENT_SUCCESS);
@@ -352,7 +352,7 @@ void KviDccRecvThread::run()
if(iFailedSelects > 3)
msleep(3 * iFailedSelects);
- if(((int)(m_pFile->pos())) == m_pOpt->iTotalFileSize)
+ if((quint64)m_pFile->pos() == m_pOpt->uTotalFileSize)
{
// Wait for the peer to close the connection
if(iProbableTerminationTime == 0)
@@ -412,10 +412,10 @@ KviDccSendThread::KviDccSendThread(QObject * par,kvi_socket_t fd,KviDccSendThrea
{
m_pOpt = opt;
// stats
- m_iAverageSpeed = -1;
- m_iInstantSpeed = -1;
- m_iFilePosition = 0;
- m_iTotalSentBytes = 0;
+ m_uAverageSpeed = 0;
+ m_uInstantSpeed = 0;
+ m_uFilePosition = 0;
+ m_uTotalSentBytes = 0;
m_pTimeInterval = new KviMSecTimeInterval();
m_uStartTime = 0;
m_uInstantSpeedInterval = 0;
@@ -438,10 +438,10 @@ void KviDccSendThread::updateStats()
if(m_pOpt->bNoAcks)
{
// There are no acks : the avg bandwidth is based on the sent bytes
- m_iAverageSpeed = m_iTotalSentBytes / uElapsedTime;
+ m_uAverageSpeed = m_uTotalSentBytes / uElapsedTime;
} else {
// acknowledges : we compute the avg bandwidth based on the acks we receive
- m_iAverageSpeed = (m_iAckedBytes - m_pOpt->iStartPosition) / uElapsedTime;
+ m_uAverageSpeed = (m_uAckedBytes - m_pOpt->uStartPosition) / uElapsedTime;
}
if(m_uInstantSpeedInterval >= INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_MSECS)
@@ -461,12 +461,12 @@ void KviDccSendThread::updateStats()
// else we have been delayed for a time comparable to a period
// and thus we can't recover the bandwidth... let it go as it does...
}
- m_iInstantSpeed = (m_iInstantSentBytes * 1000) / m_uInstantSpeedInterval;
+ m_uInstantSpeed = (m_uInstantSentBytes * 1000) / m_uInstantSpeedInterval;
m_uInstantSpeedInterval = uMSecsOfNextPeriodUsed;
- m_iInstantSentBytes = 0;
+ m_uInstantSentBytes = 0;
} else {
if(uElapsedTime <= INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_SECS)
- m_iInstantSpeed = m_iAverageSpeed;
+ m_uInstantSpeed = m_uAverageSpeed;
}
m_pMutex->unlock();
}
@@ -483,13 +483,16 @@ void KviDccSendThread::run()
m_uStartTime = m_pTimeInterval->secondsCounter();
m_pMutex->unlock();
- m_iTotalSentBytes = 0;
- m_iInstantSentBytes = 0;
+ m_uTotalSentBytes = 0;
+ m_uInstantSentBytes = 0;
int iFailedSelects = 0;
_ack_buffer ackbuffer;
int iBytesInAckBuffer = 0;
- quint32 iLastAck = 0;
-
+ quint32 uLastAck = 0;
+ quint64 uTotLastAck = 0;
+ bool bAckHack = false;
+ int iAckHackRounds = 0;
+
if(m_pOpt->iPacketSize < 32)m_pOpt->iPacketSize = 32;
char * buffer = (char *)kvi_malloc(m_pOpt->iPacketSize * sizeof(char));
@@ -507,17 +510,23 @@ void KviDccSendThread::run()
goto exit_dcc;
}
- if(m_pOpt->iStartPosition > 0)
+ if(pFile->size() >= 0xffffffff)
+ {
+ //dcc acks support only files up to 4GiB
+ bAckHack=true;
+ }
+
+ if(m_pOpt->uStartPosition > 0)
{
// seek
- if(!(pFile->seek(m_pOpt->iStartPosition)))
+ if(!(pFile->seek(m_pOpt->uStartPosition)))
{
postErrorEvent(KviError_fileIOError);
goto exit_dcc;
}
}
- iLastAck = m_pOpt->iStartPosition;
+ uLastAck = m_pOpt->uStartPosition;
for(;;)
{
@@ -553,13 +562,32 @@ void KviDccSendThread::run()
if(iBytesInAckBuffer == 4)
{
quint32 iNewAck = ntohl(ackbuffer.i32AckBuffer);
- if((iNewAck > pFile->pos()) || (iNewAck < iLastAck))
+ if(iNewAck > pFile->pos())
{
// the peer is drunk or is trying to fool us
postErrorEvent(KviError_acknowledgeError);
break;
}
- iLastAck = iNewAck;
+ if(iNewAck < uLastAck)
+ {
+ if(bAckHack)
+ {
+ //we reached the 4gb ack limit
+ iAckHackRounds++;
+ } else {
+ // the peer is drunk or is trying to fool us
+ postErrorEvent(KviError_acknowledgeError);
+ break;
+ }
+ }
+ uLastAck = iNewAck;
+ if(bAckHack)
+ {
+ uTotLastAck = (iAckHackRounds*4294967296) + iNewAck;
+ } else {
+
+ uTotLastAck = iNewAck;
+ }
iBytesInAckBuffer = 0;
}
} else {
@@ -568,10 +596,10 @@ void KviDccSendThread::run()
// update stats
m_pMutex->lock(); // is this really necessary ?
- m_iAckedBytes = iLastAck;
+ m_uAckedBytes = uTotLastAck;
m_pMutex->unlock();
- if(iLastAck >= pFile->size())
+ if(uLastAck >= (quint64)pFile->size())
{
KviThreadEvent * e = new KviThreadEvent(KVI_DCC_THREAD_EVENT_SUCCESS);
postEvent(parent(),e);
@@ -611,18 +639,18 @@ void KviDccSendThread::run()
{
if(!pFile->atEnd())
{
- if(m_pOpt->bFastSend || m_pOpt->bNoAcks || (iLastAck == pFile->pos()))
+ if(m_pOpt->bFastSend || m_pOpt->bNoAcks || (uLastAck == (quint64)pFile->pos()))
{
// maximum readable size
- int toRead = pFile->size() - pFile->pos();
+ qint64 toRead = pFile->size() - pFile->pos();
// the max number of bytes we can send in this interval (bandwidth limit)
m_pMutex->lock(); // FIXME: how to remove this lock ?
- int iMaxPossible = m_pOpt->uMaxBandwidth < MAX_DCC_BANDWIDTH_LIMIT ? m_pOpt->uMaxBandwidth * INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_SECS : MAX_DCC_BANDWIDTH_LIMIT * INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_SECS;
+ uint uMaxPossible = m_pOpt->uMaxBandwidth < MAX_DCC_BANDWIDTH_LIMIT ? m_pOpt->uMaxBandwidth * INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_SECS : MAX_DCC_BANDWIDTH_LIMIT * INSTANT_BANDWIDTH_CHECK_INTERVAL_IN_SECS;
m_pMutex->unlock();
- if(iMaxPossible < m_iInstantSentBytes)toRead = 0; // already sent too much!
+ if(uMaxPossible < m_uInstantSentBytes)toRead = 0; // already sent too much!
else {
- iMaxPossible -= m_iInstantSentBytes;
- if(toRead > iMaxPossible)toRead = iMaxPossible;
+ uMaxPossible -= m_uInstantSentBytes;
+ if(toRead > uMaxPossible)toRead = uMaxPossible;
}
// limit to packet size
if(toRead > m_pOpt->iPacketSize)toRead = m_pOpt->iPacketSize;
@@ -662,9 +690,9 @@ void KviDccSendThread::run()
}
}
- m_iTotalSentBytes += written;
- m_iInstantSentBytes += written;
- m_iFilePosition = pFile->pos();
+ m_uTotalSentBytes += written;
+ m_uInstantSentBytes += written;
+ m_uFilePosition = pFile->pos();
updateStats();
}
} else {
@@ -758,7 +786,7 @@ KviDccFileTransfer::KviDccFileTransfer(KviDccDescriptor * dcc)
m_eGeneralStatus = Connecting;
bool bOk;
- m_uTotalFileSize = dcc->bRecvFile ? dcc->szFileSize.toULong(&bOk) : dcc->szLocalFileSize.toULong(&bOk);
+ m_uTotalFileSize = dcc->bRecvFile ? dcc->szFileSize.toULongLong(&bOk) : dcc->szLocalFileSize.toULongLong(&bOk);
if(!bOk)m_uTotalFileSize = 0;
if(m_pDescriptor->bRecvFile)
@@ -912,7 +940,7 @@ void KviDccFileTransfer::abort()
if(m_pDescriptor->bRecvFile)
g_pApp->fileDownloadTerminated(false,m_pDescriptor->szFileName.toUtf8().data(),m_pDescriptor->szLocalFileName.toUtf8().data(),m_pDescriptor->szNick.toUtf8().data(),__tr_ctx("Aborted","dcc"));
- KviStr tmp;
+ QString tmp;
if(m_pSlaveRecvThread)tmp.setNum(m_pSlaveRecvThread->receivedBytes());
else if(m_pSlaveSendThread)tmp.setNum(m_pSlaveSendThread->sentBytes());
@@ -923,7 +951,7 @@ void KviDccFileTransfer::abort()
m_szStatusString = __tr2qs_ctx("Transfer failed: ","dcc");
m_szStatusString += __tr2qs_ctx("Aborted","dcc");
- KVS_TRIGGER_EVENT_3(KviEvent_OnDCCFileTransferFailed,eventWindow(),QString("Aborted by user"),QString(tmp.ptr()),m_pDescriptor->idString());
+ KVS_TRIGGER_EVENT_3(KviEvent_OnDCCFileTransferFailed,eventWindow(),QString("Aborted by user"),tmp,m_pDescriptor->idString());
outputAndLog(KVI_OUT_DCCERROR,m_szStatusString);
displayUpdate();
@@ -936,9 +964,6 @@ void KviDccFileTransfer::fillContextPopup(KviTalPopupMenu * m)
m->insertItem(__tr2qs_ctx("Resend DCC","dcc"),this,SLOT(retryDCC()));
m->insertItem(__tr2qs_ctx("Resend TDCC","dcc"),this,SLOT(retryTDCC()));
m->insertItem(__tr2qs_ctx("Resend RevDCC","dcc"),this,SLOT(retryRevDCC()));
- /* FIX ME credo che il problema sia che se riavvio un trasferimento, a sua volta gia'
- avviato, questo non ha irc contex, perche' la finestra "in cui e' nato"e' sta
- quella della dcc. Conservarsi l'id della finestra? */
int id = m->insertItem(__tr2qs_ctx("Abort","dcc"),this,SLOT(abort()));
if(!active())m->setItemEnabled(id,false);
}
@@ -1058,24 +1083,24 @@ void KviDccFileTransfer::setBandwidthLimit(int iVal)
unsigned int KviDccFileTransfer::averageSpeed()
{
- unsigned int iAvgBandwidth = 0;
+ unsigned int uAvgBandwidth = 0;
if(m_pDescriptor->bRecvFile)
{
if(m_pSlaveRecvThread)
{
m_pSlaveRecvThread->initGetInfo();
- iAvgBandwidth = (unsigned int)m_pSlaveRecvThread->averageSpeed();
+ uAvgBandwidth = m_pSlaveRecvThread->averageSpeed();
m_pSlaveRecvThread->doneGetInfo();
}
} else {
if(m_pSlaveSendThread)
{
m_pSlaveSendThread->initGetInfo();
- iAvgBandwidth = (unsigned int)m_pSlaveSendThread->averageSpeed();
+ uAvgBandwidth = m_pSlaveSendThread->averageSpeed();
m_pSlaveSendThread->doneGetInfo();
}
}
- return iAvgBandwidth;
+ return uAvgBandwidth;
}
unsigned int KviDccFileTransfer::transferredBytes()
@@ -1178,21 +1203,19 @@ void KviDccFileTransfer::displayPaint(QPainter * p,int column, QRect rect)
QFontMetrics fm(p->font());
int iW = width - 8;
- int iAvgBandwidth = -1;
- int iInstantSpeed = -1;
- int iAckedBytes = -1;
-
+ uint uAvgBandwidth = 0;
+ uint uInstantSpeed = 0;
+ quint64 uAckedBytes = 0;
+ quint64 uTransferred = 0;
int iEta = -1;
- unsigned int uTransferred = 0;
-
if(m_pDescriptor->bRecvFile)
{
if(m_pSlaveRecvThread)
{
m_pSlaveRecvThread->initGetInfo();
- iAvgBandwidth = m_pSlaveRecvThread->averageSpeed();
- iInstantSpeed = m_pSlaveRecvThread->instantSpeed();
+ uAvgBandwidth = m_pSlaveRecvThread->averageSpeed();
+ uInstantSpeed = m_pSlaveRecvThread->instantSpeed();
uTransferred = m_pSlaveRecvThread->filePosition();
m_pSlaveRecvThread->doneGetInfo();
}
@@ -1200,10 +1223,10 @@ void KviDccFileTransfer::displayPaint(QPainter * p,int column, QRect rect)
if(m_pSlaveSendThread)
{
m_pSlaveSendThread->initGetInfo();
- iAvgBandwidth = m_pSlaveSendThread->averageSpeed();
- iInstantSpeed = m_pSlaveSendThread->instantSpeed();
+ uAvgBandwidth = m_pSlaveSendThread->averageSpeed();
+ uInstantSpeed = m_pSlaveSendThread->instantSpeed();
uTransferred = m_pSlaveSendThread->filePosition();
- iAckedBytes = m_pSlaveSendThread->ackedBytes();
+ uAckedBytes = m_pSlaveSendThread->ackedBytes();
m_pSlaveSendThread->doneGetInfo();
}
}
@@ -1215,25 +1238,25 @@ void KviDccFileTransfer::displayPaint(QPainter * p,int column, QRect rect)
if(m_uTotalFileSize > 0)
{
- if(iAvgBandwidth > 0)
+ if(uAvgBandwidth > 0)
{
- unsigned int uRemaining = m_uTotalFileSize - uTransferred;
- iEta = uRemaining / iAvgBandwidth;
+ quint64 uRemaining = m_uTotalFileSize - uTransferred;
+ iEta = uRemaining / uAvgBandwidth;
}
- if(!m_pDescriptor->bNoAcks && (iAckedBytes > 0) && (iAckedBytes < ((int)(uTransferred))))
+ if(!m_pDescriptor->bNoAcks && (uAckedBytes > 0) && (uAckedBytes < uTransferred))
{
// we are sending a file and are getting acks
double dPerc1 = (double)(((double)uTransferred) * 100.0) / (double)m_uTotalFileSize;
int iL1 = (int) ((((double)iW) * dPerc1) / 100.0);
- double dPerc2 = (double)(((double)iAckedBytes) * 100.0) / (double)m_uTotalFileSize;
+ double dPerc2 = (double)(((double)uAckedBytes) * 100.0) / (double)m_uTotalFileSize;
int iL2 = (int) ((((double)iW) * dPerc2) / 100.0);
int iW2 = iL1 - iL2;
if(iW2 > 0)p->fillRect(rect.left() + 5 + iL2,rect.top() + 5,iW2,10,bIsTerminated ? QColor(150,130,110) : QColor(220,170,100));
p->fillRect(rect.left() + 5,rect.top() + 5,iL2,10,bIsTerminated ? QColor(140,110,110) : QColor(200,100,100));
- txt = QString(__tr2qs_ctx("%1 of %2 (%3%)","dcc")).arg(KviQString::makeSizeReadable(iAckedBytes)).arg(KviQString::makeSizeReadable(m_uTotalFileSize)).arg(dPerc2,0,'f',2);
+ txt = QString(__tr2qs_ctx("%1 of %2 (%3%)","dcc")).arg(KviQString::makeSizeReadable(uAckedBytes)).arg(KviQString::makeSizeReadable(m_uTotalFileSize)).arg(dPerc2,0,'f',2);
} else {
// we are receiving a file or not sending acks
double dPerc = (double)(((double)uTransferred) * 100.0) / (double)m_uTotalFileSize;
@@ -1259,14 +1282,10 @@ void KviDccFileTransfer::displayPaint(QPainter * p,int column, QRect rect)
{
txt = __tr2qs_ctx("Spd:","dcc");
txt += " ";
- if(iInstantSpeed >= 0)
- {
- QString tmpisp;
- KviNetUtils::formatNetworkBandwidthString(tmpisp,iInstantSpeed);
- txt += tmpisp;
- } else {
- txt += "? B/s";
- }
+
+ QString tmpisp;
+ KviNetUtils::formatNetworkBandwidthString(tmpisp,uInstantSpeed);
+ txt += tmpisp;
txt += " [";
} else {
txt = "";
@@ -1274,14 +1293,9 @@ void KviDccFileTransfer::displayPaint(QPainter * p,int column, QRect rect)
txt += __tr2qs_ctx("Avg:","dcc");
txt += " ";
- if(iAvgBandwidth >= 0)
- {
- QString tmpspd;
- KviNetUtils::formatNetworkBandwidthString(tmpspd,iAvgBandwidth);
- txt += tmpspd;
- } else {
- txt += "? B/s";
- }
+ QString tmpspd;
+ KviNetUtils::formatNetworkBandwidthString(tmpspd,uAvgBandwidth);
+ txt += tmpspd;
if(!bIsTerminated)
{
@@ -1696,8 +1710,8 @@ void KviDccFileTransfer::connected()
KviDccRecvThreadOptions * o = new KviDccRecvThreadOptions;
o->szFileName = m_pDescriptor->szLocalFileName.toUtf8().data();
bool bOk;
- o->iTotalFileSize = m_pDescriptor->szFileSize.toInt(&bOk);
- if(!bOk)o->iTotalFileSize = -1;
+ o->uTotalFileSize = m_pDescriptor->szFileSize.toULongLong(&bOk);
+ if(!bOk)o->uTotalFileSize = 0;
o->bResume = m_pDescriptor->bResume;
o->iIdleStepLengthInMSec = KVI_OPTION_BOOL(KviOption_boolDccSendForceIdleStep) ? KVI_OPTION_UINT(KviOption_uintDccSendIdleStepInMSec) : 0;
o->bIsTdcc = m_pDescriptor->bIsTdcc;
@@ -1713,8 +1727,8 @@ void KviDccFileTransfer::connected()
o->iIdleStepLengthInMSec = KVI_OPTION_BOOL(KviOption_boolDccSendForceIdleStep) ? KVI_OPTION_UINT(KviOption_uintDccSendIdleStepInMSec) : 0;
bool bOk;
o->bIsTdcc = m_pDescriptor->bIsTdcc;
- o->iStartPosition = m_pDescriptor->szFileSize.toInt(&bOk);
- if(!bOk || (o->iStartPosition < 0))o->iStartPosition = 0;
+ o->uStartPosition = m_pDescriptor->szFileSize.toULongLong(&bOk);
+ if(!bOk) o->uStartPosition = 0;
o->iPacketSize = KVI_OPTION_UINT(KviOption_uintDccSendPacketSize);
if(o->iPacketSize < 32)o->iPacketSize = 32;
o->uMaxBandwidth = m_uMaxBandwidth;
diff --git a/src/modules/dcc/send.h b/src/modules/dcc/send.h
index 282cab123..61f950cfd 100644
--- a/src/modules/dcc/send.h
+++ b/src/modules/dcc/send.h
@@ -54,7 +54,7 @@ class KviTalPopupMenu;
typedef struct _KviDccSendThreadOptions
{
KviStr szFileName;
- int iStartPosition;
+ quint64 uStartPosition;
int iPacketSize;
int iIdleStepLengthInMSec;
bool bFastSend;
@@ -71,25 +71,25 @@ public:
~KviDccSendThread();
private:
// stats: SHARED!!!
- int m_iAverageSpeed;
- int m_iInstantSpeed;
- int m_iFilePosition;
- int m_iAckedBytes;
- int m_iTotalSentBytes;
+ uint m_uAverageSpeed;
+ uint m_uInstantSpeed;
+ quint64 m_uFilePosition;
+ quint64 m_uAckedBytes;
+ quint64 m_uTotalSentBytes;
// internal
unsigned long m_uStartTime;
unsigned long m_uInstantSpeedInterval;
- int m_iInstantSentBytes;
+ quint64 m_uInstantSentBytes;
KviDccSendThreadOptions * m_pOpt;
KviMSecTimeInterval * m_pTimeInterval; // used for computing the instant bandwidth but not only
public:
void initGetInfo();
- int averageSpeed(){ return m_iAverageSpeed; };
- int instantSpeed(){ return m_iInstantSpeed; };
- int filePosition(){ return m_iFilePosition; };
+ uint averageSpeed(){ return m_uAverageSpeed; };
+ uint instantSpeed(){ return m_uInstantSpeed; };
+ quint64 filePosition(){ return m_uFilePosition; };
// sent ONLY in this session
- int sentBytes(){ return m_iTotalSentBytes; };
- int ackedBytes(){ return m_iAckedBytes; };
+ quint64 sentBytes(){ return m_uTotalSentBytes; };
+ quint64 ackedBytes(){ return m_uAckedBytes; };
unsigned int bandwidthLimit(){ return m_pOpt->uMaxBandwidth; };
void setBandwidthLimit(unsigned int uMaxBandwidth){ m_pOpt->uMaxBandwidth = uMaxBandwidth; };
void doneGetInfo();
@@ -102,7 +102,7 @@ typedef struct _KviDccRecvThreadOptions
{
bool bResume;
KviStr szFileName;
- int iTotalFileSize;
+ quint64 uTotalFileSize;
int iIdleStepLengthInMSec;
bool bSendZeroAck;
bool bNoAcks;
@@ -119,24 +119,24 @@ protected:
KviDccRecvThreadOptions * m_pOpt;
// stats: SHARED!
- int m_iAverageSpeed;
- int m_iInstantSpeed;
- int m_iFilePosition;
- int m_iTotalReceivedBytes;
+ uint m_uAverageSpeed;
+ uint m_uInstantSpeed;
+ quint64 m_uFilePosition;
+ quint64 m_uTotalReceivedBytes;
// internal
unsigned long m_uStartTime;
KviMSecTimeInterval * m_pTimeInterval; // used for computing the instant bandwidth
- int m_iInstantReceivedBytes;
- unsigned long m_uInstantSpeedInterval;
+ quint64 m_uInstantReceivedBytes;
+ quint64 m_uInstantSpeedInterval;
QFile * m_pFile;
public:
void initGetInfo();
- int averageSpeed(){ return m_iAverageSpeed; };
- int instantSpeed(){ return m_iInstantSpeed; };
- int filePosition(){ return m_iFilePosition; };
+ uint averageSpeed(){ return m_uAverageSpeed; };
+ uint instantSpeed(){ return m_uInstantSpeed; };
+ quint64 filePosition(){ return m_uFilePosition; };
// received ONLY in this session
- int receivedBytes(){ return m_iTotalReceivedBytes; };
+ quint64 receivedBytes(){ return m_uTotalReceivedBytes; };
unsigned int bandwidthLimit(){ return m_pOpt->uMaxBandwidth; };
void setBandwidthLimit(unsigned int uMaxBandwidth){ m_pOpt->uMaxBandwidth = uMaxBandwidth; };
void doneGetInfo();
@@ -191,7 +191,7 @@ private:
kvi_time_t m_tTransferStartTime;
kvi_time_t m_tTransferEndTime;
// cached stats
- unsigned long m_uTotalFileSize; // total file size to transfer
+ quint64 m_uTotalFileSize; // total file size to transfer
unsigned int m_uMaxBandwidth;
KviDccFileTransferBandwidthDialog * m_pBandwidthDialog;