0

I wanted to create a timeout while my program is downloading the files through an LAN FTP server. The function is to download files from a host of a FTP server, it was connected with LAN cable to the host. I have tried to set the timeout with

dWtm = 4000; InternetSession->SetOption(INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, &dWtm, 4);

but it doesn't timeout even if the downloading period is already 13 seconds. Is there an alternative where I can create a timeout to end the function after a specified period?

gansl
  • 11
  • 2
  • this worked for me you can try this method https://stackoverflow.com/questions/40550730/how-to-implement-timeout-for-function-in-c?answertab=votes#tab-top – Jose Beltran Sep 01 '20 at 03:27
  • Please include more information when asking questions related to API, such as what is the name of the library/framework being used and any relevant link to the documentation. Quick google search shows that you are probably using MFC (Microsoft Foundation Classes) API and most likely the problem is for some reason, the incorrect overload of API (with 3 parameters) is getting invoked. Probably need to cast the second parameter properly for the correct overload (with 4 parameters) to be invoked ? Also please check return value of the API to see whether setting of the option was successful or not. – vshenoy Sep 01 '20 at 08:35
  • @veshenoy you're right, I'm using MFC API. I have switched to use InternetSetOption from Wininet.h where I start creating the handle with hInternet = InternetOpen (NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); hFtpSession = InternetConnect(hInternet,lpServerName, nPort, lpUserName, lpPassword, INTERNET_SERVICE_FTP, 0, 0); InternetSetOption (hFtpSession, INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, &dwTmout, sizeof(dwTmout)); I then proceed to check the return value with InternetQueryOption, the return value is same with InternetSetOption. It still do not timeout within desired time. – gansl Sep 02 '20 at 02:36

0 Answers0