[5.30 (x86)] - ReceiveHTTPFile locks interface [RESOLVED]

Just starting out? Need help? Post your questions and find answers here.
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

[5.30 (x86)] - ReceiveHTTPFile locks interface [RESOLVED]

Post by garretthylltun »

System:
PureBasic 5.30 (Linux - x86)
Distro: elementary OS: 0.2.1 "Luna"(32-bit)
Based on: Ubuntu 12.04("Precise")
Intel Core 2 CPU 6300 @ 1.86ghz x 2
Memory: 2gb
Library/Command/Function involved:
Library: HTTP/Gadget
Command: ReceiveHTTPFile()
Symptom:
When downloading webpages using ReceiveHTTPFile, the interface is locked and you cannot update any gadgets before/between and after the file(s) are downloading(ed). For example, downloading several pages, in between the ReceiveHTTPFile for each file, I was trying to update the statusbar text with the current page to download, but the update of the statusbar is blocked/locked. This goes for other gadgets besides the statusbar. You also cannot disable or enable any other gadgets before, during or after the ReceiveHTTPFile call.
Example Code:

Code: Select all

  OpenWindow(0,60,60,450,60,"Webpage Download Example",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
  ButtonGadget(0,0,0,100,30,"Download")
  ButtonGadget(1,100,0,100,30,"Exit")
  CreateStatusBar(0,WindowID(0))
    AddStatusBarField(#PB_Ignore)
    StatusBarText(0,0,"Ready...")

EVENTLOOP:
  vWindowEvent = WaitWindowEvent()
  If vWindowEvent = #PB_Event_CloseWindow
    Goto CLOSE
  EndIf
  If vWindowEvent = #PB_Event_Gadget
    If EventGadget() = 0
      Goto DOWNLOAD_PAGES
    ElseIf EventGadget() = 1
      Goto CLOSE
    EndIf
  EndIf
  Goto EVENTLOOP

DOWNLOAD_PAGES:
  DisableGadget(0,1)
  DisableGadget(1,1)
  vWebPage.s = "http://www.freewarehome.com/index.php?"
  vPagesTotal = 30
  vCurrPage = 1
  InitNetwork()
  Repeat
    If ReceiveHTTPFile(vWebPage.s,"testwebpagedownload.txt")
      vBreakOut = 0
    Else
      MessageRequester("Download Error", "Was not able to download the requested webpage.  Either you are not connected or the server is down.")
      vBreakOut = 1
    EndIf
    DeleteFile("testwebpagedownload.txt")
    StatusBarText(0,0,"Downloading page " + Str(vCurrPage) + " of " + Str(vPagesTotal))
    vCurrPage = vCurrPage + 1
    vWebPage.s = "http://freewarehome.com/index.php?/page/" + Str(vCurrPage)
  Until vBreakOut = 1 Or vCurrPage > vPagesTotal
  DisableGadget(0,0)
  DisableGadget(1,0)
  Goto EVENTLOOP

CLOSE:
; -- End of the line my friend.
Best regards,
~Garrett
Last edited by garretthylltun on Tue Aug 05, 2014 7:07 am, edited 1 time in total.
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: [5.30 (x86)] - ReceiveHTTPFile locks interface

Post by Danilo »

You don't have any event handling within your download loop.

Try this quick fix, if you don't want to use threads or async downloading:

Code: Select all

Repeat
    If ReceiveHTTPFile(vWebPage.s,"testwebpagedownload.txt")
      vBreakOut = 0
    Else
      MessageRequester("Download Error", "Was not able to download the requested webpage.  Either you are not connected or the server is down.")
      vBreakOut = 1
    EndIf
    DeleteFile("testwebpagedownload.txt")
    StatusBarText(0,0,"Downloading page " + Str(vCurrPage) + " of " + Str(vPagesTotal))
    vCurrPage = vCurrPage + 1
    vWebPage.s = "http://freewarehome.com/index.php?/page/" + Str(vCurrPage)
    
    While WindowEvent():Wend ; quick fix, process all events
    
Until vBreakOut = 1 Or vCurrPage > vPagesTotal
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

Re: [5.30 (x86)] - ReceiveHTTPFile locks interface

Post by garretthylltun »

*/shakes head

Really.... You know, if there had been mention of that in the docs I wouldn't have posted about this and now I feel like a noob.. Well, I am a noob, but you get my drift.

BTW, is this the intended behaviour for ReceiveHTTPFile?

And thank you so very much for the code,
~Garrett
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: [5.30 (x86)] - ReceiveHTTPFile locks interface

Post by Danilo »

garretthylltun wrote:BTW, is this the intended behaviour for ReceiveHTTPFile?
It is a general thing, not ReceiveHTTPFile() only, although it is a blocking operation
that waits until the file is downloaded.

This would be the same:

Code: Select all

count = 1
Repeat
    Delay(1000)
    count + 1
    StatusBarText(0,0,"Loop number: " + Str(count))
    
    ;While WindowEvent():Wend ; quick fix, process all events
    
Until count >= 30
You need to make sure that events get always processed, at any time. When downloading many or big
files, you should put that in a thread or use a non-blocking download operation. I think there are some
codes for that in the forum.

EDIT: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzip) could be what you want.
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

Re: [5.30 (x86)] - ReceiveHTTPFile locks interface

Post by garretthylltun »

Ah, Ok.

Again, many thanks, I really thought it was a bug.

~Garrett
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
Post Reply