aboutsummaryrefslogtreecommitdiff
path: root/examples/http-server
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-04 17:06:09 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-04 17:06:09 -0400
commit0b8074154e2671691050bdb3bcb33245625a056c (patch)
tree1410e0c4e05c6372e876cd08f16d117e12868f41 /examples/http-server
parentfadcb45baf1274e06cfe37b87655b9146aa52874 (diff)
First working compile of refactor to add explicit typing to declarations
and support untyped empty collections and `none`s
Diffstat (limited to 'examples/http-server')
-rw-r--r--examples/http-server/connection-queue.tm2
-rw-r--r--examples/http-server/http-server.tm6
2 files changed, 4 insertions, 4 deletions
diff --git a/examples/http-server/connection-queue.tm b/examples/http-server/connection-queue.tm
index a198f091..362dab7b 100644
--- a/examples/http-server/connection-queue.tm
+++ b/examples/http-server/connection-queue.tm
@@ -3,7 +3,7 @@ use pthreads
func _assert_success(name:Text, val:Int32; inline):
fail("$name() failed!") if val < 0
-struct ConnectionQueue(_connections=@[:Int32], _mutex=pthread_mutex_t.new(), _cond=pthread_cond_t.new()):
+struct ConnectionQueue(_connections:@[Int32]=@[], _mutex=pthread_mutex_t.new(), _cond=pthread_cond_t.new()):
func enqueue(queue:ConnectionQueue, connection:Int32):
queue._mutex:lock()
queue._connections:insert(connection)
diff --git a/examples/http-server/http-server.tm b/examples/http-server/http-server.tm
index f7338b91..56ba3683 100644
--- a/examples/http-server/http-server.tm
+++ b/examples/http-server/http-server.tm
@@ -17,7 +17,7 @@ use ./connection-queue.tm
func serve(port:Int32, handler:func(request:HTTPRequest -> HTTPResponse), num_threads=16):
connections := ConnectionQueue()
- workers := &[:@pthread_t]
+ workers : &[@pthread_t] = &[]
for i in num_threads:
workers:insert(pthread_t.new(func():
repeat:
@@ -82,7 +82,7 @@ struct HTTPRequest(method:Text, path:Text, version:Text, headers:[Text], body:Te
body := rest[-1]
return HTTPRequest(method, path, version, headers, body)
-struct HTTPResponse(body:Text, status=200, content_type="text/plain", headers={:Text=Text}):
+struct HTTPResponse(body:Text, status=200, content_type="text/plain", headers:{Text=Text}={}):
func bytes(r:HTTPResponse -> [Byte]):
body_bytes := r.body:bytes()
extra_headers := (++: "$k: $v$(\r\n)" for k,v in r.headers) or ""
@@ -114,7 +114,7 @@ enum RouteEntry(ServeFile(file:Path), Redirect(destination:Text)):
return HTTPResponse("Found", 302, headers={"Location"=destination})
func load_routes(directory:Path -> {Text=RouteEntry}):
- routes := &{:Text=RouteEntry}
+ routes : &{Text=RouteEntry} = &{}
for file in (directory ++ (./*)):glob():
skip unless file:is_file()
contents := file:read() or skip