Skip to content

Commit

Permalink
ch07 finished
Browse files Browse the repository at this point in the history
- I'm giving up, can't make `curlAsync.run` work correctly.
  • Loading branch information
spamegg1 committed Aug 16, 2024
1 parent 79f5c30 commit eb1d70f
Showing 1 changed file with 118 additions and 6 deletions.
124 changes: 118 additions & 6 deletions src/main/scala/ch07/curlAsync/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ def run: Unit = // I got rid of command line arguments, easier to run.
println("initializing loop")
given ExecutionContext = EventLoop // used by onComplete

val urls = Seq(
"https://www.example.com",
"https://duckduckgo.com",
"https://www.google.com"
val urls = Seq( // more than 1 URL causes double-free or corrupt size vs prev size
"https://www.example.com"
// "https://duckduckgo.com",
// "https://www.google.com"
)

val resp = Zone:
val _ = Zone:
for url <- urls do // asynchronously make GET requests to multiple websites
val resp = Curl.startRequest(GET, url)

resp.onComplete:
resp.onComplete: // this does not trigger!
case Success(data) =>
println(s"got response for ${url} - length ${data.body.size}")
println(s"headers:")
Expand All @@ -31,3 +31,115 @@ def run: Unit = // I got rid of command line arguments, easier to run.

EventLoop.run()
println("done running async event loop with multi curl requests")

// ❯ ./project
// initializing loop
// initializing curl
// initialized multiHandle Ptr@65471d9ac720
// setting up curl socket callback with multiHandle
// setting up curl timer callback with multiHandle
// initializing libuv loop timer with curl timer callback: scala.scalanative.unsafe.CFuncPtr3@5822c462
// uv_timer_init returned 0
// done initializing
// initializing handle Ptr@65471d9afec0 for request 1
// easy_setopt returned 0
// easy_setopt returned 0
// easy_setopt returned 0
// easy_setopt returned 0
// easy_setopt returned 0
// easy_setopt returned 0
// start_timer called with timeout 0 ms
// setting effective timeout to 1
// starting timer
// uv_timer_start returned 0
// done handling messages
// request initialized
// uv_prepare_init returned 0
// in timeout callback
// uv_run returned 0
// socketCB called with action 1
// initializing handle for socket Ptr@d
// uv_poll_init_socket returned 0
// multi_assign returned 0
// starting poll with events 1
// start_timer called with timeout 1 ms
// starting timer
// uv_timer_start returned 0
// done handling messages
// on_timer fired, 1 sockets running
// in timeout callback
// start_timer called with timeout 2 ms
// starting timer
// uv_timer_start returned 0
// done handling messages
// on_timer fired, 1 sockets running
// ready_for_curl fired with status 0 and events 1
// socketCB called with action 4
// stopping poll
// start_timer called with timeout 1 ms
// starting timer
// uv_timer_start returned 0
// done handling messages
// socketCB called with action 2
// initializing handle for socket Ptr@d
// uv_poll_init_socket returned 0
// multi_assign returned 0
// starting poll with events 2
// start_timer called with timeout 0 ms
// setting effective timeout to 1
// starting timer
// uv_timer_start returned 0
// done handling messages
// multi_socket_action 0
// in timeout callback
// start_timer called with timeout 200 ms
// starting timer
// uv_timer_start returned 0
// done handling messages
// on_timer fired, 1 sockets running
// ready_for_curl fired with status 0 and events 2
// socketCB called with action 1
// starting poll with events 1
// multi_socket_action 0
// in timeout callback
// on_timer fired, 1 sockets running
// ready_for_curl fired with status 0 and events 1
// multi_socket_action 0
// ready_for_curl fired with status 0 and events 1
// multi_socket_action 0
// ready_for_curl fired with status 0 and events 1
// multi_socket_action 0
// ready_for_curl fired with status 0 and events 1
// multi_socket_action 0
// ready_for_curl fired with status 0 and events 1
// multi_socket_action 0
// ready_for_curl fired with status 0 and events 1
// multi_socket_action 0
// ready_for_curl fired with status 0 and events 1
// multi_socket_action 0
// ready_for_curl fired with status 0 and events 1
// req 1: got header line of size 1 x 13
// req 1: got header line of size 1 x 13
// req 1: got header line of size 1 x 31
// req 1: got header line of size 1 x 40
// req 1: got header line of size 1 x 37
// req 1: got header line of size 1 x 31
// req 1: got header line of size 1 x 40
// req 1: got header line of size 1 x 46
// req 1: got header line of size 1 x 26
// req 1: got header line of size 1 x 23
// req 1: got header line of size 1 x 14
// req 1: got header line of size 1 x 22
// req 1: got header line of size 1 x 2
// req 1: got data of size 1 x 1256
// socketCB called with action 4
// stopping poll
// start_timer called with timeout 1 ms
// starting timer
// uv_timer_start returned 0
// done handling messages
// multi_socket_action 0
// in timeout callback
// on_timer fired, 0 sockets running
// uv_run returned 0
// done running async event loop with multi curl requests

0 comments on commit eb1d70f

Please sign in to comment.