author | Michael Krelin <hacker@klever.net> | 2006-07-02 22:16:25 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2006-07-02 22:16:25 (UTC) |
commit | 577427e68ef10a4d2b75d28e42b22952ae3bcf23 (patch) (side-by-side diff) | |
tree | 24c8fc94ea6524059cab7927ef76639bb1a1a98d /PumpKINDlg.cpp | |
parent | 24e693797daef020ece3fa19bb5acce000e37165 (diff) | |
download | pumpkin-577427e68ef10a4d2b75d28e42b22952ae3bcf23.zip pumpkin-577427e68ef10a4d2b75d28e42b22952ae3bcf23.tar.gz pumpkin-577427e68ef10a4d2b75d28e42b22952ae3bcf23.tar.bz2 |
Do not close RRQ socket until the last ACK is received.
git-svn-id: http://svn.klever.net/kin/pumpkin/trunk@152 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | PumpKINDlg.cpp | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp index 070f3e8..2a01918 100644 --- a/PumpKINDlg.cpp +++ b/PumpKINDlg.cpp @@ -574,20 +574,20 @@ BOOL tftp::Send(CAsyncSocket *socket,SOCKADDR_IN* saddr) {
ASSERT(socket);
int rv = socket->SendTo(udpBase(),length,(SOCKADDR*)saddr,sizeof(SOCKADDR_IN));
if(rv!=length)
return FALSE;
return TRUE;
}
-void CXferSocket::DoSelect()
+void CXferSocket::DoSelect(BOOL do_select)
{
if(m_Peer.sin_addr.s_addr!=INADDR_NONE)
- AsyncSelect(FD_CLOSE|FD_READ|(m_Queue.IsEmpty()?0:FD_WRITE));
+ AsyncSelect(FD_CLOSE|FD_READ|((m_Queue.IsEmpty()&&!do_select)?0:FD_WRITE));
}
void CXferSocket::OnReceive(int nErrorCode)
{
if(nErrorCode){
ASSERT(m_Daddy);
m_Daddy->LogLine(IDS_LOG_XFERRECEIVE);
return;
@@ -849,21 +849,17 @@ tftp *p = tftp::Allocate(tftp::tftpDATA::tftpSize(m_blkSize)); TRY{
m_File.Seek(m_ACK*m_blkSize,CFile::begin);
int bytes = m_File.Read(p->data.m_DATA.data,m_blkSize);
p->data.m_DATA.SetBlock(m_ACK+1);
p->length=p->length-m_blkSize+bytes;
m_LastSlack = m_blkSize-bytes;
PostTFTP(p);
if(bytes<m_blkSize){
- state=stateFinish;
- ASSERT(m_Daddy);
- CString tmp;
- tmp.Format(IDS_LOG_XFERRRQFINISHED,(LPCTSTR)m_FileName);
- m_Daddy->LogLine(tmp);
+ state=stateClosing; m_ACKtoClose = m_ACK+1;
}
}CATCH(CFileException,e){
Deny(e);
}END_CATCH
}
UINT tftp::tftpDATA::tftpSize(UINT blkSize)
{
@@ -931,49 +927,57 @@ ULONG CRRQSocket::GetACK(void) return (m_ACK*m_blkSize)-m_LastSlack;
}
BOOL CRRQSocket::OnTFTP(tftp* p)
{
BOOL rv = TRUE;
switch(p->Opcode()){
case tftp::opOACK:
- m_ACK=0;
- ASSERT(state!=stateFinish);
- {
- tftp::tftpOptions o;
- if(p->GetOptions(&o)){
- CString v;
- if(o.Lookup(tftpoBSize,v)){
- m_blkSize=atoi(v);
- if(!m_blkSize){ // *** More sanity checks
- Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
- rv = TRUE;
- break;
+ {
+ m_ACK=0;
+ ASSERT(state!=stateFinish);
+ tftp::tftpOptions o;
+ if(p->GetOptions(&o)){
+ CString v;
+ if(o.Lookup(tftpoBSize,v)){
+ m_blkSize=atoi(v);
+ if(!m_blkSize){ // *** More sanity checks
+ Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE);
+ rv = TRUE;
+ break;
+ }
}
- }
- if(o.Lookup(tftpoTOut,v)){
- m_timeOut=atoi(v);
- if(!m_timeOut){ // *** More sanity checks
- Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
- rv = TRUE;
- break;
+ if(o.Lookup(tftpoTOut,v)){
+ m_timeOut=atoi(v);
+ if(!m_timeOut){ // *** More sanity checks
+ Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT);
+ rv = TRUE;
+ break;
+ }
+ }
+ if(o.Lookup(tftpoXResume,v)){
+ m_ACK=atoi(v);
}
}
- if(o.Lookup(tftpoXResume,v)){
- m_ACK=atoi(v);
- }
+ UpdateList();
+ DoXfer();
}
- UpdateList();
- DoXfer();
- }
break;
case tftp::opACK:
m_ACK=p->data.m_ACK.Block();
- if(state!=stateFinish){
+ if(state==stateClosing && m_ACK==m_ACKtoClose) {
+ state = stateFinish;
+ ASSERT(m_Daddy);
+ CString tmp;
+ tmp.Format(IDS_LOG_XFERRRQFINISHED,(LPCTSTR)m_FileName);
+ m_Daddy->LogLine(tmp);
+ rv = FALSE;
+ DoSelect(TRUE);
+ }else if(state!=stateFinish){
UpdateList();
DoXfer();
}
break;
case tftp::opERROR:
{
ASSERT(m_Daddy);
CString tmp;
|