|
-
March 29th, 2007, 06:18 PM
#1
ATL COM w/ WININET
All,
I am a bit confused on this and I know the forum can help.
My objective is to create and ftp client via wininet api.
This client is an ATL COM Automation Object DLL that encapsulates
wininet api in the getfile() function.
I call that DLL in an ATL COM EXE Client via an import directive.
and want to run multiple instances of the ftpclient object.
#import "E:\cmftp\ReleaseMinDependency\cmftp.dll" \
no_namespace
I use this to instanciate the pointer .
CComPtr<Istandardclient> ftpclient;
I then populate the object instance with variable data as:
ftpclient->put_servername(_bstr_t("xxx.xxx.xxx.xxx"));
ftpclient->put_username(_bstr_t("username"));
ftpclient->put_password(_bstr_t("password"));
ftpclient->put_port(21);
ftpclient->put_mode(FALSE);
ftpclient->put_infile(_bstr_t("arts.exe"));
ftpclient->put_indirectory(_bstr_t(""));
ftpclient->put_outdirectory(_bstr_t("C:\\"));
ftpclient->put_outfile(_bstr_t("arts.exe"));
I then execute the objects get function (wininet) as:
ftpclient->getfile();
Well this works great if I run the instances concurrent.
Concurrently it will run all night long transfering files.
My goal is to spawn several concurrent worker threads each with an instance of the ftp object.
I created an Init function that spawns 4 workers in the client app and if I run them without executting the ftpclient->getfile() I successfully create and execute seperate instances of the FTP Object properly.
If I enable the ftpclient->getfile()
(wich is the funtion that initiates and executes wininet functionality.)
I get a critical error and app quits.
Any one have any ideas.
I can post more code when needed.
MGP
-
March 30th, 2007, 02:35 PM
#2
Re: ATL COM w/ WININET
Looks like a multi-thread problem not necessarily related to ATL or WinInet.
You should initialize a new WinInet session from scratch on each thread. Other than that, WinInet is thread safe. I assume you store all session pointers as member variables inside your FTPClient class.
Henri Hein
Principal Engineer, Propel
Do not credit Propel with my views or opinions.
-
April 18th, 2007, 03:29 PM
#3
Re: ATL COM w/ WININET
Got that fixed as it was as you said.
NowI have another problem internal to the ftp client object.
1. primary thread connects to the database to get all the schedules.
2. worker thread waits for the thread que to fill from database then starts
spawning worker threads with the ftpclient mentioned above.
In the ftp client I am using FtpGetFile. That works well.
I can spawn seporate threads and wait till they finish no problem.
As I watch the directory fill with files as it should, I also watch a sniffer to validate the ftp communication process. It works perfectly up to the point the sockect server returns a 226 tranfer complete.
When the tranfer completes the thread ends and the file erases.
This is a constant occurence and is on a one to one basis.
So as each socket completes pass or fail ie 226 or 5xx socket error
the file disapearse after the socket returns a code.
As I watch I realize the the FtpGetFile creates a local file handle and maintains is internal to the api call.
It seems as if the API call is not closing the localfile handle before the call completes. I know this is not true because it is returning ERROR_SUCCEEDED from the FtpGetFile api call soit should be complete
and allinternal handles closed.
When I take the same code out of the service exe and use a standard exe.
The code is essentially the same except the exe waits for all threads to complete and then ends completely and the service exe waits for all currenly running threads to complete before spawning more.
The standard exe leaves the files complete and in tact.
Any suggestions on that.
-
April 19th, 2007, 02:05 PM
#4
Re: ATL COM w/ WININET
When you say "service exe," do you mean you are running your process as a service? What happens if you set up your service to run under your own account instead of the system account?
Do you use CreateFile() to open the files? What creation disposition and sharing mode do you use?
Henri Hein
Principal Engineer, Propel
Do not credit Propel with my views or opinions.
-
April 19th, 2007, 07:48 PM
#5
Re: ATL COM w/ WININET
No actually the function GetFtpFile does the file creation for me.
one of the values passed in to the function is output file name.
I think the problem is still in the thread handling, because when the code runs in a standard exe, and waitsformultipleobjects ie thread handles before exiting all works properly, but when I run the exe with a thread that monitors the database and a thread that spawns worker threads for ftpclient creation and file retreival the file writes properly but when the socket ftpclient finishes with a 226 transfer complete the file erases.
Just like if you start a console ftp process and let it run almost to completed and kill the ftp process the file is created and then erases.
The only caviot there is that the file completes as the sniffer tells me so, and as soon as it completesthe file disapears.
It is very strange as it is not directly related to the ftp client object because as I said the flp client works properly when it is called in a web page or a standard exe.
I think it has to be something in my threading, but I am not 100% sure.
I am going to work with a couple tests and try to get different results.
Thanks,
MGP
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|