Skip to content

Commit

Permalink
ch10 edits
Browse files Browse the repository at this point in the history
  • Loading branch information
spamegg1 committed Apr 14, 2024
1 parent 5af165d commit 4469e7c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/ch10/loop.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch10.libUvService
package ch10

import scalanative.unsafe.*
import scalanative.libc.stdlib
import scalanative.libc.stdlib.malloc
import collection.mutable.ListBuffer
import concurrent.{ExecutionContext, ExecutionContextExecutor}
import concurrent.{Future, Promise}
Expand All @@ -12,7 +12,7 @@ object EventLoop extends ExecutionContextExecutor:

val loop = uv_default_loop()
private val taskQueue = ListBuffer[Runnable]()
private val handle = stdlib.malloc(uv_handle_size(UV_PREPARE_T))
private val handle = malloc(uv_handle_size(UV_PREPARE_T))
checkError(uv_prepare_init(loop, handle), "uv_prepare_init")

val prepareCallback = CFuncPtr1.fromScalaFunction[PrepareHandle, Unit]:
Expand Down
6 changes: 2 additions & 4 deletions src/main/scala/ch10/parsing.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package ch10.libUvService
package ch10

import scalanative.unsafe.*
import scalanative.libc.*
import scalanative.unsigned.*
import stdlib.*, stdio.*, string.*
import scalanative.unsigned.UShort
import collection.mutable

case class RequestState(
Expand Down
13 changes: 5 additions & 8 deletions src/main/scala/ch10/server.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package ch10.libUvService
package ch10

import scalanative.unsigned.UnsignedRichLong
import scalanative.unsafe.*
import scalanative.libc.*
import scalanative.unsigned.*
import stdlib.*, stdio.*, string.*
import scalanative.libc.{stdlib, string, stdio}
import stdlib.malloc, string.{strncpy, strlen}
import collection.mutable
import concurrent.{Future, ExecutionContext}

Expand Down Expand Up @@ -40,7 +39,7 @@ case class AsyncRoute(
object Server extends Parsing:
import ch07.LibUVConstants.*, ch07.LibUV.*, HttpParser.*

implicit val ec: ExecutionContext = EventLoop
given ec: ExecutionContext = EventLoop
val loop = EventLoop.loop
var serial = 1L
override val requests = mutable.Map[Long, RequestState]()
Expand Down Expand Up @@ -90,8 +89,7 @@ object Server extends Parsing:
val id = serial
serial += 1

val state = malloc(sizeof[ConnectionState])
.asInstanceOf[Ptr[ConnectionState]]
val state = malloc(sizeof[ConnectionState]).asInstanceOf[Ptr[ConnectionState]]
state._1 = serial
state._2 = client
http_parser_init(state.at3, HTTP_REQUEST)
Expand Down Expand Up @@ -158,7 +156,6 @@ object Server extends Parsing:
else resp.headers

for (k, v) <- headers do respString += s"${k}: $v\r\n"

respString += s"\r\n${resp.body}"

val buffer = malloc(sizeof[Buffer]).asInstanceOf[Ptr[Buffer]]
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/ch10/service.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ch10.libUvService
package ch10

import util.boundary, boundary.break
import concurrent.{Future, ExecutionContext}
Expand Down

0 comments on commit 4469e7c

Please sign in to comment.