CPU spike when using wxFTP, wxURL Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
DarkHorizon
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Sep 22, 2006 5:07 pm

CPU spike when using wxFTP, wxURL

Post by DarkHorizon »

Hi all,

Longtime (10+ years) C++ programmer here, just getting into protocol-based wx classes.

Some info:
- Windows XP SP2
- app will eventually be used in Linux and Mac OS X
- wxWidgets version is 2.6.3 installed from wxPack (had problems getting a wx build environment set up, so opted for the simpler install)
- haven't tried the below code on other OS in order to see if I could duplicate these problems
- I'm not running firewall or antivirus software; none have been installed on this desktop
- Desktop PC connects to the internet via an iptables firewall running on Ubuntu 6.10, which permits NAT'd outbound connections (which incidentally work fine :))

I've been trying to download a HTML file from my webserver for parsing, and it seems anytime I use a wx class which touches the network, the application halts, and the CPU hangs at around 99%.

I followed the documented wxFTP tutorial, using the following code to make a connection to my FTP server ...

Code: Select all

wxFTP ftp;

ftp.SetUser(_("user"));
ftp.SetPassword(_("pass"));
if (ftp.Connect(_("host.com")))
{
	ftp.Close();
}
... however the application hangs upon calling ftp.Connect().

I also tried making a HTTP connection, as follows ...

Code: Select all

wxURL url(_("http://someurl.com/index.html"));
url.GetInputStream();
... however this similarly hangs upon calling GetInputStream().

I've tried using fully qualified domain names as well as IP addresses, so I know the problem is not with DNS. I haven't really tested much to see if there's a timeout period which is not being reached for whatever reason (though I have let the app hang for about a minute, it doesn't return).

Not sure what to do at this point; could there be something broken internally on my system?
nusi
Knows some wx things
Knows some wx things
Posts: 30
Joined: Thu Aug 24, 2006 7:43 pm

Post by nusi »

In what state is your program, when you try to get the data?

If your application and the main frame didn't initialize so far [if it's not within wxApp::OnRun()], than calling wxSocket::GetInputStream() will virtually halt your program.

Please try the hint given in this post: http://forums.wxwidgets.org/viewtopic.php?p=45125#45125

Look for "YourAppTraits".
DarkHorizon
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Sep 22, 2006 5:07 pm

Post by DarkHorizon »

Hi there,

I did some checking and testing. The wxGUIAppTraits class is only part of wxWidgets 2.8, so is not an option to me.

I was calling this code within the wxFrame constructor. I tested the code in the wxApp::OnRun() and wxApp::OnInit() functions instead, and the app resulted in the same.

Any ideas?
JSThePatriot
Earned some good credits
Earned some good credits
Posts: 146
Joined: Sun Nov 26, 2006 7:37 am
Location: Tennessee, USA
Contact:

Post by JSThePatriot »

I don't know if you get the samples in the wxPack that you do in the release download, but there is a sockets example in there that shows you how to properly use wxURL(), I would recommend you try running that sample application, and see if it hangs as well. If it doesn't then maybe you can fashion your code more in that direction.

Unfortunately that is all I can offer at the moment.
JS
DarkHorizon
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Sep 22, 2006 5:07 pm

Post by DarkHorizon »

Well, I managed to fix the problem.

I upgraded to wxWidgets 2.8, I found the same problem.

I also tried calling wxSocketBase::Initialize() inside wxApp::OnInit() before any other networking code, but that didn't work either.

After some testing, I placed my network code inside a wxThread... this worked. The application executes without locking up.

I can live with this (I needed threading for other application purposes anyway), but it seems a bit strange that this was necessary. I'm obviously doing something else wrong, but I'm really not sure what it is!

Thanks for your replies, if anyone else finds an alternate solution I'd be interested in hearing it.

Best regards,
PhoenixPl
I live to help wx-kind
I live to help wx-kind
Posts: 179
Joined: Wed Feb 15, 2006 9:26 am

Post by PhoenixPl »

Unfortunately I had the same problem. Right now the only solution is to put wxFTP/wxURL in secondary thread and god knows what difference it makes.
Post Reply