how to make it threadsafe? I want to use it for stress-testing my api server, thank you.
Code: Select all
[00:36:12] Waiting for executable to start...
[00:36:12] Executable type: Windows - x86 (32bit, Unicode, Thread, Purifier)
[00:36:12] Executable started.
[00:36:14] [ERROR] Line: 17
[00:36:14] [ERROR] Overflow in a string memory block.
[00:37:02] Waiting for executable to start...
[00:37:02] Executable type: Windows - x86 (32bit, Unicode, Thread, Purifier)
[00:37:02] Executable started.
[00:37:06] [ERROR] Line: 29
[00:37:06] [ERROR] Overflow in a string memory block.
[00:40:09] Executable type: Windows - x86 (32bit, Unicode, Thread, Purifier)
[00:40:09] Executable started.
[00:40:17] [ERROR] pb_curl.pbi (Line: 1045)
[00:40:17] [ERROR] Invalid memory access. (read error at address 4)
https://github.com/deseven/pbsamples/tr ... rm/libcurl
Code: Select all
IncludeFile "pb_curl.pbi"
; working with static libcurl
InitNetwork()
Procedure liqu_post(tread)
; Debug "Thread on: "+Str(tread)
Protected curl = curl_easy_init()
Protected url.s = str2curl("http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1")
Protected agent.s = str2curl("pbcurl/1.0")
; cookie.s = str2curl("var=value;")
; post.s = str2curl("login=mylogin&password=mypassword")
Protected header.s = str2curl("Cache-Control: no-cache")
Protected time_start, res, time_end, resData.s
If curl
curl_easy_setopt(curl,#CURLOPT_URL,@url)
curl_easy_setopt(curl,#CURLOPT_IPRESOLVE,#CURL_IPRESOLVE_V4)
; curl_easy_setopt(curl,#CURLOPT_COOKIE,@cookie)
; curl_easy_setopt(curl,#CURLOPT_POSTFIELDS,@post)
curl_easy_setopt(curl,#CURLOPT_USERAGENT,@agent)
curl_easy_setopt(curl,#CURLOPT_TIMEOUT,30)
curl_easy_setopt(curl,#CURLOPT_FOLLOWLOCATION,1)
*header = curl_slist_append(0,header)
curl_easy_setopt(curl,#CURLOPT_HTTPHEADER,*header)
curl_easy_setopt(curl,#CURLOPT_WRITEFUNCTION,@curlWriteData())
time_start = ElapsedMilliseconds()
res = curl_easy_perform(curl)
time_end = ElapsedMilliseconds() - time_start
resData = curlGetData()
curl_easy_getinfo(curl,#CURLINFO_RESPONSE_CODE,@resHTTP)
Debug Str(tread)+" HTTP result: " + Str(res)
If Not res
Debug Str(tread)+" : "+Str(time_end) + " ms"
Debug Str(tread)+" HTTP code: " + Str(resHTTP)
Debug Str(tread)+" HTTP data: " + #CRLF$ + resData
EndIf
curl_easy_cleanup(curl)
Else
Debug Str(tread)+" can't init curl!"
EndIf
EndProcedure
Procedure liqu_repeat_post(thread)
Repeat
liqu_post(thread)
Delay(100)
ForEver
EndProcedure
Repeat
i=i+1
CreateThread(@liqu_repeat_post(), i)
Delay(20)
Until i>100
Repeat
Delay(500000)
ForEver