Curl fix
Need to work on mutex (maybe with http://forum.purebasic.com/english/viewtopic.php?f=13&t=61006)
This commit is contained in:
56
osm.pb
56
osm.pb
@@ -30,6 +30,8 @@ DeclareModule OSM
|
|||||||
Declare SetCallBackLocation(*CallBackLocation)
|
Declare SetCallBackLocation(*CallBackLocation)
|
||||||
Declare LoadGpxFile(file.s);
|
Declare LoadGpxFile(file.s);
|
||||||
Declare AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1)
|
Declare AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1)
|
||||||
|
Declare Quit()
|
||||||
|
Declare Error(msg.s)
|
||||||
EndDeclareModule
|
EndDeclareModule
|
||||||
|
|
||||||
Module OSM
|
Module OSM
|
||||||
@@ -124,6 +126,7 @@ Module OSM
|
|||||||
Dirty.i ;To signal that drawing need a refresh
|
Dirty.i ;To signal that drawing need a refresh
|
||||||
CurlMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :(((((
|
CurlMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :(((((
|
||||||
|
|
||||||
|
MainDrawingThread.i
|
||||||
List TilesThreads.TileThread()
|
List TilesThreads.TileThread()
|
||||||
|
|
||||||
List track.Location() ;to display a GPX track
|
List track.Location() ;to display a GPX track
|
||||||
@@ -133,6 +136,10 @@ Module OSM
|
|||||||
|
|
||||||
Global OSM.OSM, Null.i
|
Global OSM.OSM, Null.i
|
||||||
|
|
||||||
|
Procedure Error(msg.s)
|
||||||
|
Debug msg, 2
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
;- *** CURL specific ***
|
;- *** CURL specific ***
|
||||||
|
|
||||||
Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s
|
Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s
|
||||||
@@ -146,13 +153,13 @@ Module OSM
|
|||||||
If *ReceiveHTTPToMemoryBuffer = 0
|
If *ReceiveHTTPToMemoryBuffer = 0
|
||||||
*ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper)
|
*ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper)
|
||||||
If *ReceiveHTTPToMemoryBuffer = 0
|
If *ReceiveHTTPToMemoryBuffer = 0
|
||||||
; Debug "Problem allocating memory"
|
Debug "Problem allocating memory"
|
||||||
End
|
End
|
||||||
EndIf
|
EndIf
|
||||||
Else
|
Else
|
||||||
*ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper)
|
*ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper)
|
||||||
If *ReceiveHTTPToMemoryBuffer = 0
|
If *ReceiveHTTPToMemoryBuffer = 0
|
||||||
; Debug "Problem reallocating memory"
|
Debug "Problem reallocating memory"
|
||||||
End
|
End
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
@@ -171,7 +178,7 @@ Module OSM
|
|||||||
;Debug "ReceiveHTTPToMemory" + URL$ + ProxyURL$ + ProxyPort$ + ProxyUser$ + ProxyPassword$
|
;Debug "ReceiveHTTPToMemory" + URL$ + ProxyURL$ + ProxyPort$ + ProxyUser$ + ProxyPassword$
|
||||||
|
|
||||||
If Len(URL$)
|
If Len(URL$)
|
||||||
|
|
||||||
curl = curl_easy_init()
|
curl = curl_easy_init()
|
||||||
|
|
||||||
If curl
|
If curl
|
||||||
@@ -181,7 +188,8 @@ Module OSM
|
|||||||
curl_easy_setopt(curl, #CURLOPT_URL, str2curl(URL$))
|
curl_easy_setopt(curl, #CURLOPT_URL, str2curl(URL$))
|
||||||
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0)
|
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0)
|
||||||
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0)
|
curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0)
|
||||||
curl_easy_setopt(curl, #CURLOPT_HEADER, 0)
|
curl_easy_setopt(curl, #CURLOPT_HEADER, 0)
|
||||||
|
curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 1)
|
||||||
curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout)
|
curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout)
|
||||||
|
|
||||||
If Len(ProxyURL$)
|
If Len(ProxyURL$)
|
||||||
@@ -201,9 +209,12 @@ Module OSM
|
|||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToMemoryFunction())
|
curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToMemoryFunction())
|
||||||
|
LockMutex(OSM\CurlMutex)
|
||||||
res = curl_easy_perform(curl)
|
res = curl_easy_perform(curl)
|
||||||
|
UnlockMutex(OSM\CurlMutex)
|
||||||
|
|
||||||
If res = #CURLE_OK
|
If res = #CURLE_OK
|
||||||
|
|
||||||
*Buffer = AllocateMemory(ReceiveHTTPToMemoryBufferPtr)
|
*Buffer = AllocateMemory(ReceiveHTTPToMemoryBufferPtr)
|
||||||
If *Buffer
|
If *Buffer
|
||||||
CopyMemory(*ReceiveHTTPToMemoryBuffer, *Buffer, ReceiveHTTPToMemoryBufferPtr)
|
CopyMemory(*ReceiveHTTPToMemoryBuffer, *Buffer, ReceiveHTTPToMemoryBufferPtr)
|
||||||
@@ -278,13 +289,34 @@ Module OSM
|
|||||||
ClosePreferences()
|
ClosePreferences()
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
curl_global_init(#CURL_GLOBAL_ALL);
|
curl_global_init(#CURL_GLOBAL_WIN32);
|
||||||
|
|
||||||
;- Main drawing thread launching
|
;- Main drawing thread launching
|
||||||
CreateThread(@DrawingThread(), @OSM\Drawing)
|
OSM\MainDrawingThread = CreateThread(@DrawingThread(), @OSM\Drawing)
|
||||||
|
If OSM\MainDrawingThread = 0
|
||||||
|
Error("MapGadget : Can't create main drawing thread")
|
||||||
|
End
|
||||||
|
EndIf
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure Quit()
|
||||||
|
;kill main drawing thread
|
||||||
|
KillThread(OSM\MainDrawingThread)
|
||||||
|
|
||||||
|
;wait for loading threads to finish nicely
|
||||||
|
ResetList( OSM\TilesThreads())
|
||||||
|
While NextElement(OSM\TilesThreads())
|
||||||
|
If IsThread(OSM\TilesThreads()\GetImageThread) = 0
|
||||||
|
FreeMemory(OSM\TilesThreads()\Tile)
|
||||||
|
DeleteElement(OSM\TilesThreads())
|
||||||
|
ResetList( OSM\TilesThreads())
|
||||||
|
EndIf
|
||||||
|
Wend
|
||||||
|
|
||||||
|
curl_global_cleanup()
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
Macro Min(a,b)
|
Macro Min(a,b)
|
||||||
(Bool((a) <= (b)) * (a) + Bool((b) < (a)) * (b))
|
(Bool((a) <= (b)) * (a) + Bool((b) < (a)) * (b))
|
||||||
EndMacro
|
EndMacro
|
||||||
@@ -452,9 +484,9 @@ Module OSM
|
|||||||
Debug "Check if we have this image on Web"
|
Debug "Check if we have this image on Web"
|
||||||
|
|
||||||
If Proxy
|
If Proxy
|
||||||
LockMutex(OSM\CurlMutex) ;Seems no more necessary
|
;LockMutex(OSM\CurlMutex)
|
||||||
*Buffer = CurlReceiveHTTPToMemory(TileURL, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$)
|
*Buffer = CurlReceiveHTTPToMemory(TileURL, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$)
|
||||||
UnlockMutex(OSM\CurlMutex)
|
;UnlockMutex(OSM\CurlMutex)
|
||||||
Else
|
Else
|
||||||
*Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous
|
*Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous
|
||||||
EndIf
|
EndIf
|
||||||
@@ -1051,12 +1083,14 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
ResizeAll()
|
ResizeAll()
|
||||||
EndSelect
|
EndSelect
|
||||||
Until Quit = #True
|
Until Quit = #True
|
||||||
|
|
||||||
|
OSM::Quit()
|
||||||
EndIf
|
EndIf
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
|
|
||||||
; IDE Options = PureBasic 5.42 LTS (Windows - x86)
|
; IDE Options = PureBasic 5.42 LTS (Windows - x86)
|
||||||
; CursorPosition = 245
|
; CursorPosition = 213
|
||||||
; FirstLine = 235
|
; FirstLine = 188
|
||||||
; Folding = -------
|
; Folding = -------
|
||||||
; EnableUnicode
|
; EnableUnicode
|
||||||
; EnableThread
|
; EnableThread
|
||||||
|
Reference in New Issue
Block a user