Fun
0.41.5
The programming language that makes You have fun
Main Page
Data Structures
Files
File List
Globals
Loading...
Searching...
No Matches
src
vm
os
socket_send.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
21
22
case
OP_SOCK_SEND
: {
23
/* Pops data string, fd; pushes bytes sent (>=0) or -1 */
24
Value
datav
= pop_value(vm);
25
Value
fdv
= pop_value(vm);
26
int
sent
= -1;
27
#ifdef __unix__
28
if
(
fdv
.type !=
VAL_INT
||
datav
.type !=
VAL_STRING
) {
29
fprintf
(stderr,
"Runtime type error: sock_send expects (int fd, string data)\n"
);
30
free_value
(
datav
);
31
free_value
(
fdv
);
32
push_value
(vm,
make_int
(-1));
33
break
;
34
}
35
int
fd
= (int)
fdv
.i;
36
const
char
*
buf
=
datav
.s ?
datav
.s :
""
;
37
size_t
len
= strlen(
buf
);
38
ssize_t
n
= send(
fd
,
buf
,
len
, 0);
39
if
(
n
>= 0)
40
sent
= (int)
n
;
41
else
42
sent
= -1;
43
#endif
44
free_value
(
datav
);
45
free_value
(
fdv
);
46
push_value
(vm,
make_int
(
sent
));
47
break
;
48
}
OP_SOCK_SEND
@ OP_SOCK_SEND
Definition
bytecode.h:223
fdv
Value fdv
Definition
fd_poll_read.c:25
len
size_t len
Definition
input_line.c:102
buf
char * buf
Definition
input_line.c:103
n
int n
Definition
insert.c:41
datav
Value datav
Definition
serial_config.c:31
fd
int fd
Definition
serial_open.c:92
sent
int sent
Definition
serial_send.c:30
free_value
free_value(datav)
push_value
push_value(vm, make_int(sent))
Value
Tagged union representing a Fun value.
Definition
value.h:68
make_int
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition
value.c:51
VAL_STRING
@ VAL_STRING
Definition
value.h:53
VAL_INT
@ VAL_INT
Definition
value.h:51
fprintf
#define fprintf
Definition
vm.c:200
Generated on
for Fun by
1.16.1