Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
socket_tcp_accept.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
20
22 /* Pops listen fd; pushes client fd (>0) or 0 */
23 Value fdv = pop_value(vm);
24 int client = 0;
25#ifdef __unix__
26 if (fdv.type != VAL_INT) {
27 fprintf(stderr, "Runtime type error: tcp_accept expects (int listen_fd)\n");
29 push_value(vm, make_int(0));
30 break;
31 }
32 int s = (int)fdv.i;
33 int c = accept(s, NULL, NULL);
34 if (c >= 0) client = c;
35#endif
38 break;
39}
@ OP_SOCK_TCP_ACCEPT
Definition bytecode.h:221
Value fdv
Value c
Definition load_const.c:31
uint32_t s
Definition rol.c:31
int client
free_value(fdv)
push_value(vm, make_int(client > 0 ? client :0))
Tagged union representing a Fun value.
Definition value.h:68
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51
@ VAL_INT
Definition value.h:51
#define fprintf
Definition vm.c:200