wxURL GetInputStream woes

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
Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

wxURL GetInputStream woes

Post by Ksmith22 » Tue Jan 03, 2006 7:56 pm

I've been researching this for about a week now and there seems to be some problem with wxURL's GetInputStream.

In a nutshell, this post from the Mailing Lists explains the problem I'm having:
http://thread.gmane.org/gmane.comp.lib. ... evel/65707

Basically I'm trying to read in a file from a URL and put that into a wxInputStream, but the program hangs when it gets to the GetInputStream line.

From what I can tell there seems to be a bug in the wxURL (or wxSocket?) source code, but I can't seem to find a definative solution to fixing it. I tried looking for a patch or something on the CVS but couldn't really find anything relevant (unless I missed it). Does anyone have a solution for fixing this? I'm completely stumped.

Lamego
Earned some good credits
Earned some good credits
Posts: 101
Joined: Wed Jun 29, 2005 10:13 pm
Location: Portugal
Contact:

Same here

Post by Lamego » Tue Jan 03, 2006 9:11 pm

I found the same problem some time ago.
The only thing I can tell you is that this is specific to wxMSW (I have tried the same code on wxGTK and worked fine).
Meanwhile I have continued working on other parts of my application but now I am also needing this...

P.S.: The function does not hang completely, it will timeout after a long period, if you set a shorter timeout into the object socket it will return sooner (not that it helps much).
wxMSW 2.6.3 - GCC 3.4.2 (MinGW/MSYS)
wxGTK 2.6.3 - GCC 4.02 (Ubuntu)
Code::Blocks Win/Lin
PTlink Tech Admin
PTlink Chat Software Lead Developer
http://software.pt-link.net

Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Re: Same here

Post by Ksmith22 » Tue Jan 03, 2006 9:43 pm

Lamego wrote:I found the same problem some time ago.
The only thing I can tell you is that this is specific to wxMSW (I have tried the same code on wxGTK and worked fine).
Meanwhile I have continued working on other parts of my application but now I am also needing this...

P.S.: The function does not hang completely, it will timeout after a long period, if you set a shorter timeout into the object socket it will return sooner (not that it helps much).
Yeah, I discovered that about MSW as well.

I've been trying to do the same thing, work on other parts, but it is getting to the point where I'm going to need to get this fixed soon. The way I have it now where I set it up using wxFileSystem (which unfortunately uses wxURL for its internet protocol -_-) *works* but only if the file is local on my hard drive. Theoretically I should be able to replace that path with an http:// URL and have it work once whatever is wrong with wxURL is fixed.

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Wed Jan 04, 2006 9:54 am

have you called wxSocketBase::Initialize() in your OnInit()?

Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post by Ksmith22 » Wed Jan 04, 2006 3:04 pm

lowjoel wrote:have you called wxSocketBase::Initialize() in your OnInit()?
Yes, it did nothing :(

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Thu Jan 05, 2006 1:22 am

tried using wxURL in a thread?

Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post by Ksmith22 » Thu Jan 05, 2006 2:57 pm

lowjoel wrote:tried using wxURL in a thread?
I did originally though it wasn't a wxThread (it was whatever threading system process.h uses.. I believe it's Microsoft's system). I could try it with a wxThread though (I've since switched over) if you think that would work.

I think the problem is that I am calling this in the OnInit() because I need to setup an image for part of the GUI. According to that mailing list topic that seems to be what is causing the problem. I'm not quite sure how I would do it another way though.

Just for reference, this is my code (it's in a function that's called during OnInit):

Code: Select all

	wxFileSystem::AddHandler(new wxInternetFSHandler);

	wxFileSystem ad1_url;
	wxFSFile* ad1_file = ad1_url.OpenFile("http://www.google.com/intl/en/images/logo.gif");

	wxInputStream *in1 = ad1_file->GetStream();
	wxBitmap* ad1img = new wxBitmap(wxImage(*in1,wxBITMAP_TYPE_GIF).Scale(88,25));
And then that is put into a panel for display. It works perfectly fine if the image is on my hard drive, but as soon as I change the path to an http it hangs.

In Visual Studio .NET 2003's Disassembly this is the line it hangs on:

Code: Select all

005E990E  call        wxFileSystem::OpenFile (5ADB33h) 
I think though the reason wxFileSystem has trouble with OpenFile whereas wxURL only has trouble with GetInputStream is because that's the part of the code where the URL is actually tried to be read.

Edit: I'm stepping through the code right now and indeed wxFileSystem calls wxURL's GetInputStream (which is what I figured was the case). As soon as I find it I'll try to post the exact line in the source it seems to get stuck on.

Edit2: The line is in http.cpp:

Code: Select all

    if (!BuildRequest(path, m_post_buf.empty() ? wxHTTP_GET : wxHTTP_POST))
        return NULL;
Or more deeply in protocol.cpp:

Code: Select all

    while ( sock->WaitForRead() )
It seems WaitForRead() causes an infinite loop. All this of course originating in the wxURL GetInputStream call :P

Edit3: Ran across this on the lists:
http://thread.gmane.org/gmane.comp.lib. ... eral/18425

Someone wrote up a whole call stack basically relating the same problem. That's exactly what I observed with mine.

Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post by Ksmith22 » Thu Jan 05, 2006 6:29 pm

Ok, I've come up with a partial workaround though it is not the greatest.

In http.cpp, line 261, I changed:

Code: Select all

    m_perr = ReadLine(this, tmp_str);
To:

Code: Select all

    m_perr = GetLine(this, tmp_str);
And then recompiled the net library. THAT worked, though from what I've read GetLine is somewhat broken (though at this point I don't care as long as it works here). So if anyone has a better solution perhaps involving a fix of ReadLine let me know.

The net library is generating a few warnings now though in Release build. Still works, but I'm curious if anyone knows how to get rid of these (maybe it's a problem with GetLine):

Code: Select all

wxbase26_net.lib(gsocket.obj) : warning LNK4049: locally defined symbol _free imported

wxbase26_net.lib(ftp.obj) : warning LNK4049: locally defined symbol _free imported

wxbase26_net.lib(sckaddr.obj) : warning LNK4049: locally defined symbol _free imported

wxbase26_net.lib(socket.obj) : warning LNK4049: locally defined symbol _free imported

wxbase26_net.lib(protocol.obj) : warning LNK4217: locally defined symbol _free imported in function "public: __thiscall wxCharBuffer::wxCharBuffer(unsigned int)" ([email protected]@[email protected]@Z)

wxbase26_net.lib(fs_inet.obj) : warning LNK4217: locally defined symbol _free imported in function "public: void __thiscall wxStringData::Unlock(void)" ([email protected]@@QAEXXZ)

wxbase26_net.lib(url.obj) : warning LNK4049: locally defined symbol _free imported

wxbase26_net.lib(sckfile.obj) : warning LNK4049: locally defined symbol _free imported

wxbase26_net.lib(http.obj) : warning LNK4049: locally defined symbol _free imported

etc...

jdx
In need of some credit
In need of some credit
Posts: 3
Joined: Mon Jan 09, 2006 7:33 am

Check your runtime libraries

Post by jdx » Mon Jan 09, 2006 8:06 am

Ksmith22 wrote: The net library is generating a few warnings now though in Release build. Still works, but I'm curious if anyone knows how to get rid of these (maybe it's a problem with GetLine):

Code: Select all

wxbase26_net.lib(gsocket.obj) : warning LNK4049: locally defined symbol _free imported

wxbase26_net.lib(ftp.obj) : warning LNK4049: locally defined symbol _free imported

etc...
This looks like your libraries are linked to different run-time versions. Make sure that all your libraries link to the same runtime, be it multi-threaded, dll, or debug versions.

Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Re: Check your runtime libraries

Post by Ksmith22 » Mon Jan 09, 2006 2:52 pm

jdx wrote:
Ksmith22 wrote: The net library is generating a few warnings now though in Release build. Still works, but I'm curious if anyone knows how to get rid of these (maybe it's a problem with GetLine):

Code: Select all

wxbase26_net.lib(gsocket.obj) : warning LNK4049: locally defined symbol _free imported

wxbase26_net.lib(ftp.obj) : warning LNK4049: locally defined symbol _free imported

etc...
This looks like your libraries are linked to different run-time versions. Make sure that all your libraries link to the same runtime, be it multi-threaded, dll, or debug versions.
Yup, that was it. I built in Multithreaded (not DLL) mode but for some reason that library's Release build was still set to Multithreaded DLL.

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Mon May 08, 2006 7:11 am

This appers to still around in 2.6.3 and in fact the latest ANSI version of DialogBlocks on my Windows XP/Turion has this same problem and is unable to load a URL.

EDIT:I guess this one was fixed, must be another one...
Last edited by Ryan Norton on Mon May 08, 2006 4:08 pm, edited 1 time in total.
[Mostly retired moderator, still check in to clean up some stuff]

Lamego
Earned some good credits
Earned some good credits
Posts: 101
Joined: Wed Jun 29, 2005 10:13 pm
Location: Portugal
Contact:

working here

Post by Lamego » Mon May 08, 2006 10:26 am

The issue got resolved for me with 2.6.3 ...
wxMSW 2.6.3 - GCC 3.4.2 (MinGW/MSYS)
wxGTK 2.6.3 - GCC 4.02 (Ubuntu)
Code::Blocks Win/Lin
PTlink Tech Admin
PTlink Chat Software Lead Developer
http://software.pt-link.net

Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post by Ksmith22 » Mon May 08, 2006 2:05 pm

Yeah this actually worked for me in 2.6.3 as well.

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Thu May 11, 2006 7:38 pm

In case anyone is curious, I spent quite a few hours on it and figured out my problem as well - see the thread, "[wx-dev] A conundrum - wxHtmlWindow::LoadPage in wxApp::OnInit " on wx-dev:

http://lists.wxwidgets.org/cgi-bin/ezml ... hgbaehcf#b
[Mostly retired moderator, still check in to clean up some stuff]

achim
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Sun Aug 29, 2004 5:20 pm
Location: Germany

Post by achim » Fri May 12, 2006 2:55 pm

hi,

according to my threat of september 2004, I want to annotate, that it works
with 2.6.3 for me too.

cheers
achim

Post Reply