Skip to main content

rl_lang/interpreter/stdlib/net/
mod.rs

1//! `std::net` - TCP/UDP networking built directly on `std::net`.
2
3use crate::interpreter::native::Module;
4use std::net::{TcpListener, TcpStream, UdpSocket};
5
6mod common;
7mod resolve;
8mod tcp_accept;
9mod tcp_close;
10mod tcp_connect;
11mod tcp_listen;
12mod tcp_local_addr;
13mod tcp_peer_addr;
14mod tcp_read;
15mod tcp_set_nonblocking;
16mod tcp_set_timeout;
17mod tcp_shutdown;
18mod tcp_write;
19mod udp_bind;
20mod udp_close;
21mod udp_connect;
22mod udp_recv;
23mod udp_recv_from;
24mod udp_send;
25mod udp_send_to;
26
27pub const KEYWORDS: &[&str] = &[
28    "tcp_listen",
29    "tcp_accept",
30    "tcp_connect",
31    "tcp_read",
32    "tcp_write",
33    "tcp_peer_addr",
34    "tcp_local_addr",
35    "tcp_set_timeout",
36    "tcp_set_nonblocking",
37    "tcp_shutdown",
38    "tcp_close",
39    "udp_bind",
40    "udp_connect",
41    "udp_send",
42    "udp_send_to",
43    "udp_recv",
44    "udp_recv_from",
45    "udp_close",
46    "resolve",
47];
48
49/// A single native networking resource, stored behind an `int` handle.
50pub enum NetHandle {
51    TcpListener(TcpListener),
52    TcpStream(TcpStream),
53    UdpSocket(UdpSocket),
54}
55
56pub fn module() -> Module {
57    Module::new("net")
58        .with_function("tcp_listen", tcp_listen::func)
59        .with_function("tcp_accept", tcp_accept::func)
60        .with_function("tcp_connect", tcp_connect::func)
61        .with_function("tcp_read", tcp_read::func)
62        .with_function("tcp_write", tcp_write::func)
63        .with_function("tcp_peer_addr", tcp_peer_addr::func)
64        .with_function("tcp_local_addr", tcp_local_addr::func)
65        .with_function("tcp_set_timeout", tcp_set_timeout::func)
66        .with_function("tcp_set_nonblocking", tcp_set_nonblocking::func)
67        .with_function("tcp_shutdown", tcp_shutdown::func)
68        .with_function("tcp_close", tcp_close::func)
69        .with_function("udp_bind", udp_bind::func)
70        .with_function("udp_connect", udp_connect::func)
71        .with_function("udp_send", udp_send::func)
72        .with_function("udp_send_to", udp_send_to::func)
73        .with_function("udp_recv", udp_recv::func)
74        .with_function("udp_recv_from", udp_recv_from::func)
75        .with_function("udp_close", udp_close::func)
76        .with_function("resolve", resolve::func)
77}