Skip to content

Commit 4d74f17

Browse files
committed
Make bind non-async
1 parent b195321 commit 4d74f17

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

libraries/common/io/network.effekt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ namespace internal {
7171
ret void
7272
"""
7373

74-
extern async def bind(host: String, port: Int): Int =
74+
extern io def bind(host: String, port: Int): Int =
7575
llvm """
76-
call void @c_tcp_bind(%Pos ${host}, %Int ${port}, %Stack %stack)
77-
ret void
76+
%result = call %Int @c_tcp_bind(%Pos ${host}, %Int ${port})
77+
ret %Int %result
7878
"""
7979

8080
extern async def listen(listener: Int, handler: Int => Unit at {io, async, global}): Int =

libraries/llvm/io.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ void c_tcp_close(Int handle, Stack stack) {
316316
uv_close(uv_handle, c_tcp_close_cb);
317317
}
318318

319-
void c_tcp_bind(String host, Int port, Stack stack) {
320-
// TODO make non-async
319+
Int c_tcp_bind(String host, Int port) {
321320
char* host_str = c_bytearray_into_nullterminated_string(host);
322321
erasePositive(host);
323322

@@ -327,8 +326,7 @@ void c_tcp_bind(String host, Int port, Stack stack) {
327326
if (result < 0) {
328327
free(tcp_handle);
329328
free(host_str);
330-
resume_Int(stack, result);
331-
return;
329+
return result;
332330
}
333331

334332
struct sockaddr_in addr;
@@ -337,18 +335,16 @@ void c_tcp_bind(String host, Int port, Stack stack) {
337335

338336
if (result < 0) {
339337
uv_close((uv_handle_t*)tcp_handle, (uv_close_cb)free);
340-
resume_Int(stack, result);
341-
return;
338+
return result;
342339
}
343340

344341
result = uv_tcp_bind(tcp_handle, (const struct sockaddr*)&addr, 0);
345342
if (result < 0) {
346343
uv_close((uv_handle_t*)tcp_handle, (uv_close_cb)free);
347-
resume_Int(stack, result);
348-
return;
344+
return result;
349345
}
350346

351-
resume_Int(stack, (int64_t)tcp_handle);
347+
return (int64_t)tcp_handle;
352348
}
353349

354350
typedef struct {

0 commit comments

Comments
 (0)