Re: CFtpFindFile freezes
Hi,
Thank you for the response..
[short version]
Randomly, between CFtpFileFind::FindFile and looping
CFtpFileFind::FindNextFile, my internet FTP connection hangs. It is
less likely to hang if a Sleep(N) is added to the loop. The bigger N
is, the less likely it is to hang. Though large Ns is slowing the
program down too much. Any ideas what's going on?
****
First rule: if your multithreaded code doesn't work unless you add a Slee=
p() call, your
design is wrong. You have not stated if this is multithreaded. Is i=
t really the
CFtpFile::FindNextFile that hangs? Or is it something else? Since y=
ou haven't shown any
code, we are left to try to debug by psychic vibrations, never a viable s=
olution.
****
Sorry, the application is not multi-threaded and does not use
asynchronous calls.
I have implemented a new high-speed logging mechanism (that doesn't
delay long enough to alter the results) and have found the exact line
of code that freezes to be ftpFind.FindFile("*.*");
Here is just the FTP code extracted from the actual code:
// This whole block of code loops for each unique log-in details
(distinct IPAddress, UserName, Password)
// {{
if(m_pInetSession != NULL)
delete m_pInetSession;
m_pInetSession = new CInternetSession
( m_LogType
, 1
, PRE_CONFIG_INTERNET_ACCESS
, NULL
, NULL
, INTERNET_FLAG_DONT_CACHE
);
m_pFtpConnection = m_pInetSession->GetFtpConnection
( IPAddress
, UserName
, Password
);
....
// This block of code loops for each directory on the server
// {{
BOOL bContinue = ftpFind.FindFile ("*.*");
while (bContinue)
{
bContinue = ftpFind.FindNextFile();
...
}
ftpFind.Close();
// }} END: This block of code loops for each directory on the server
....
m_pFtpConnection->Close( );
// }} END: This whole block of code loops for each unique log-in
details
I added code that writes a log entry immediately before and
immediately after each of these lines of code, and normally they all
execute instantly (within the resolution of the log's timer) but when
it fails, there's a log entry before { BOOL bContinue =
ftpFind.FindFile ("*.*"); } and then the one after is exactly
300000(+-16) milliseconds later, and then everything else fails until
the next connection is established. There are other FTP commands, like
setting directories, and putting and getting files, but logging shows
these don't need to execute for the problem to show itself (so I
haven't included them).
This error can happen on the very first call to FindFile since the
program is run, or it can happen after iterating through several
different servers, and several hundred different directories. The
program terminates after it is completed (so it is always a fresh
start)
****
See first rule. If the design is wrong, sprinkling Sleep() calls aroun=
d like pixie dust
only makes the problem go away until the basic error creeps in again due =
to timing issues.
****
Sleep and pixie-dust, my two favourite things :)
Any ideas?
****
Not without a better description.
joe
****
Thanks again,
Kind regards,
Eliott