Skip to content

Commit 710d05e

Browse files
committed
compiler bug workaround
1 parent a79ed1d commit 710d05e

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

lightbug_http/strings.mojo

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ alias rChar = String("\r")._buffer
1212
alias nChar = String("\n")._buffer
1313

1414

15+
struct S[lifetime: MutLifetime]:
16+
var s: Reference[String, __mlir_attr.`1: i1`, lifetime] # zero is immut
17+
18+
fn __init__(
19+
inout self, s: Reference[String, __mlir_attr.`1: i1`, lifetime]
20+
) -> None:
21+
self.s = s
22+
23+
1524
# TODO: tuples don't work with strings in Mojo currently, to be replaced with a tuple
1625
@value
1726
struct TwoLines:

lightbug_http/sys/net.mojo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,23 @@ struct SysConnection(Connection):
181181

182182
fn write(self, buf: Bytes) raises -> Int:
183183
let msg = String(buf)
184+
print("Sending response: " + msg)
184185
if send(self.fd, to_char_ptr(msg).bitcast[c_void](), len(msg), 0) == -1:
185186
print("Failed to send response")
186187
return len(buf)
187188

188-
async fn write_async(self, buf: Bytes) raises -> Int:
189-
print("write_async " + b64decode(buf))
190-
189+
# This has to be a def for now because of a weird bug in the Mojo compiler
190+
async def write_async(self, buf: Bytes) -> Int:
191191
@parameter
192-
async fn task() -> Int:
192+
async def task(task_buf: Bytes) -> Int:
193193
try:
194-
let write_len = self.write(buf)
194+
let write_len = self.write(task_buf)
195195
return write_len
196196
except e:
197197
print("Failed to write to connection: " + e.__str__())
198198
return -1
199199

200-
let routine: Coroutine[Int] = task()
200+
let routine: RaisingCoroutine[Int] = task(buf)
201201
return await routine
202202

203203
fn close(self) raises:

lightbug_http/sys/server.mojo

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from lightbug_http.service import HTTPService
88
from lightbug_http.io.sync import Duration
99
from lightbug_http.io.bytes import Bytes, to_bytes, to_string
1010
from lightbug_http.error import ErrorHandler
11-
from lightbug_http.strings import next_line, NetworkType
11+
from lightbug_http.strings import next_line, NetworkType, S
1212
from external.b64 import encode as b64_encode
1313

1414

@@ -100,10 +100,9 @@ struct SysServer:
100100
header,
101101
)
102102
)
103-
var res_encoded: String = encode(res)
103+
var res_encoded = encode(res)
104104
try:
105-
let write_len = await conn.write_async(res_encoded._buffer)
106-
print(write_len)
105+
_ = await conn.write_async(res_encoded)
107106
except e:
108107
print("Ooph! " + e.__str__())
109108
try:

0 commit comments

Comments
 (0)