IMA with HTTPRequest() inside threads

Just starting out? Need help? Post your questions and find answers here.
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

IMA with HTTPRequest() inside threads

Post by dige »

Hi guys, I have a problem with httpRequest() inside a thread. Occasionally there is an illegal memory access.

I use the asynchronous access to be able to abort on a timeout.

First I had IMA's with FinishHTTP() because I forgot to abort the request with AbortHTTP() at the timeout.

But now the errors occur with AbortHTTP().

My question is: the following code, is it a good construct in principle or do you see something that is misapplied?

Code: Select all

HttpRequest = HTTPRequest(#PB_HTTP_Get, Url, Param, #PB_HTTP_NoSSLCheck|#PB_HTTP_Asynchronous, Header$())
  
  If HttpRequest
    
    
    Repeat
      Progress = HTTPProgress(HttpRequest)
      
      Select Progress
        Case #PB_HTTP_Success
          StatusCode = HTTPInfo(HTTPRequest, #PB_HTTP_StatusCode)
          Result = HTTPInfo(HTTPRequest, #PB_HTTP_Response)
          Break

        Case #PB_HTTP_Failed
          Debug "Download failed"
          Break

        Case #PB_HTTP_Aborted
          Debug "Download aborted"
          Break
          
        Default
          If TimeOut < Date()
            AbortHTTP(HttpRequest)
            Break
          EndIf
          
          Delay(50)

      EndSelect

    ForEver
    
    FinishHTTP(HttpRequest)

May be, is FinishHTTP(HttpRequest) after AbortHTTP(HttpRequest) a problem?

Glad to get any help.

Dige
"Daddy, I'll run faster, then it is not so far..."
Fred
Administrator
Administrator
Posts: 16618
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: IMA with HTTPRequest() inside threads

Post by Fred »

AbortHTTP() just set a flag to actually stop the request, you can't call FinishHTTP() unless you got the '#PB_HTTP_Aborted' Status. Just remove the 'Break' after AbortHTTP() and it should be OK.
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: IMA with HTTPRequest() inside threads

Post by dige »

Thank you Fred!
"Daddy, I'll run faster, then it is not so far..."
Post Reply