Skip to content

Commit

Permalink
ch03 reorganize packages
Browse files Browse the repository at this point in the history
  • Loading branch information
spamegg1 committed Apr 8, 2024
1 parent 0a2b900 commit 692d8ba
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/ch03/common.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ch03.common
package ch03

import scalanative.posix.sys.socket.{AF_UNSPEC, SOCK_STREAM, socket, sockaddr, connect}
import scalanative.posix.netdb.{addrinfo, getaddrinfo}
Expand Down
7 changes: 3 additions & 4 deletions src/main/scala/ch03/httpClient.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package ch03.http
package ch03
package http

import scalanative.unsafe.{Zone, Ptr, CInt, CString, toCString, fromCString, CQuote}
import scalanative.unsafe.{stackalloc, extern}
Expand All @@ -7,8 +8,6 @@ import scalanative.libc.{stdio, stdlib, string}
import stdio.{FILE, fclose}

import collection.mutable.{Map => MMap}
import ch03.common
import common.util

// These are Scala strings, they will be converted to C-strings later.
case class HttpRequest(
Expand Down Expand Up @@ -136,5 +135,5 @@ def httpClient(args: String*): Unit =
val (port, path) = (toCString(args(1)), args(2)) // requires Zone
stdio.printf(c"looking up address: %s port: %s\n", address, port) // no println (Zone)

val sock = common.makeConnection(address, port) // establish connection
val sock = makeConnection(address, port) // establish connection
handleConnection(sock, host, path) // do request / response on connection
8 changes: 3 additions & 5 deletions src/main/scala/ch03/tcpClient.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package ch03.tcp
package ch03
package tcp

import scalanative.unsafe.{Zone, Ptr, toCString, fromCString, CQuote, CString}
import scalanative.libc.{stdio, stdlib}
import stdio.{FILE, fgets, fclose}

import ch03.common
import common.util

// used in handleConnection
def makeRequest(sock: Ptr[FILE], request: String): String =
// sending request and receiving response thru socket is low-level (C), so allocate.
Expand Down Expand Up @@ -80,5 +78,5 @@ def tcpClient(args: String*): Unit =
val sock = Zone: // implicit z => // 0.5
val (address, port) = (toCString(args(0)), toCString(args(1))) // requires Zone
stdio.printf(c"looking up address: %s port: %s\n", address, port)
common.makeConnection(address, port) // looks up address, returns socket
makeConnection(address, port) // looks up address, returns socket
handleConnection(sock) // gets response from socket and prints it.

0 comments on commit 692d8ba

Please sign in to comment.