mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
host_env: export vsock, wasm socket, Darwin flags (#8779)
* host_env: export vsock, wasm socket, Darwin flags Publish vsock/UDPLITE/SOL fallbacks, wasm socket and errno constants, remaining BSD chflags, and S_IFDOOR/PORT/WHT. Assisted-by: Claude * stdlib: take vsock, wasm socket, Darwin flags from host_env _socket, wasm _socket/_io/errno, _stat, and openssl alerts now re-export the host_env names. Assisted-by: Claude * host_env: keep wasm socket/errno off emscripten wasm32-unknown-emscripten is unix, so the stub modules must be unknown-unknown (and WASI) only. Assisted-by: Claude * stdlib: match socket module_def cfg to the module Assisted-by: Claude * host_env: drop duplicate Windows SOL_UDP The IANA fallback also compiled on Windows, colliding with the WinSock definition. Assisted-by: Claude
This commit is contained in:
1 parent
eb1546ae08
commit
979ea4c4dc
12 files changed
+245
-293
No files matched your search
@@ -0,0 +1,10 @@
|
||||
//! Errno numbers for `wasm32-unknown-unknown`.
|
||||
//!
|
||||
//! There is no libc errno table. The values are the Linux ABI the stdlib
|
||||
//! and `OSError` subclasses match against.
|
||||
|
||||
pub mod errors {
|
||||
pub const EAGAIN: i32 = 11;
|
||||
pub const ECONNABORTED: i32 = 103;
|
||||
pub const ECONNRESET: i32 = 104;
|
||||
}
|
||||
@@ -9,6 +9,9 @@ pub use macros::*;
|
||||
pub mod ctypes;
|
||||
#[cfg(any(unix, windows, target_os = "wasi"))]
|
||||
pub mod errno;
|
||||
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
|
||||
#[path = "errno_wasm.rs"]
|
||||
pub mod errno;
|
||||
#[cfg(any(unix, windows, target_os = "wasi"))]
|
||||
pub mod io;
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
@@ -44,6 +47,9 @@ pub mod fcntl;
|
||||
pub mod select;
|
||||
#[cfg(any(unix, windows))]
|
||||
pub mod socket;
|
||||
#[cfg(any(all(target_arch = "wasm32", target_os = "unknown"), target_os = "wasi"))]
|
||||
#[path = "socket_wasm.rs"]
|
||||
pub mod socket;
|
||||
#[cfg(unix)]
|
||||
pub mod syslog;
|
||||
#[cfg(all(unix, not(target_os = "redox"), not(target_os = "ios")))]
|
||||
|
||||
@@ -60,6 +60,42 @@ pub const SF_SUPPORTED: u32 = 0x009f0000;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub const SF_SYNTHETIC: u32 = 0xc0000000;
|
||||
|
||||
/// BSD `chflags` bits libc binds on macOS and `_stat.c` falls back to
|
||||
/// elsewhere. Published by `_stat` on every platform.
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use libc::{
|
||||
SF_APPEND, SF_ARCHIVED, SF_IMMUTABLE, UF_APPEND, UF_COMPRESSED, UF_HIDDEN, UF_IMMUTABLE,
|
||||
UF_NODUMP, UF_OPAQUE,
|
||||
};
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const UF_NODUMP: u32 = 0x00000001;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const UF_IMMUTABLE: u32 = 0x00000002;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const UF_APPEND: u32 = 0x00000004;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const UF_OPAQUE: u32 = 0x00000008;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const UF_COMPRESSED: u32 = 0x00000020;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const UF_HIDDEN: u32 = 0x00008000;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const SF_ARCHIVED: u32 = 0x00010000;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const SF_IMMUTABLE: u32 = 0x00020000;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const SF_APPEND: u32 = 0x00040000;
|
||||
|
||||
/// Solaris door/port and BSD whiteout. `_stat` publishes 0 where the
|
||||
/// platform has no such file type.
|
||||
pub const S_IFDOOR: u32 = 0;
|
||||
pub const S_IFPORT: u32 = 0;
|
||||
pub const S_IFWHT: u32 = if cfg!(target_os = "macos") {
|
||||
0o160000
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
#[cfg(not(any(unix, windows, target_os = "wasi")))]
|
||||
pub fn rename(
|
||||
from: impl AsRef<std::path::Path>,
|
||||
|
||||
@@ -181,6 +181,88 @@ pub const CAN_BCM_RX_RTR_FRAME: i32 = 0x0400;
|
||||
#[cfg(target_os = "linux")]
|
||||
pub const CAN_BCM_CAN_FD_FRAME: i32 = 0x0800;
|
||||
|
||||
/// `linux/vm_sockets.h`. libc does not bind the vsock sockopt / cid names.
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
pub const SO_VM_SOCKETS_BUFFER_SIZE: u32 = 0;
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
pub const SO_VM_SOCKETS_BUFFER_MIN_SIZE: u32 = 1;
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
pub const SO_VM_SOCKETS_BUFFER_MAX_SIZE: u32 = 2;
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
pub const VMADDR_CID_ANY: u32 = 0xffff_ffff;
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
pub const VMADDR_PORT_ANY: u32 = 0xffff_ffff;
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
pub const VMADDR_CID_HOST: u32 = 2;
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
pub const VM_SOCKETS_INVALID_VERSION: u32 = 0xffff_ffff;
|
||||
|
||||
/// `netinet/udplite.h`. libc does not bind the coverage sockopts.
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
target_os = "fuchsia",
|
||||
target_os = "freebsd",
|
||||
target_os = "linux"
|
||||
))]
|
||||
pub const UDPLITE_SEND_CSCOV: i32 = 10;
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
target_os = "fuchsia",
|
||||
target_os = "freebsd",
|
||||
target_os = "linux"
|
||||
))]
|
||||
pub const UDPLITE_RECV_CSCOV: i32 = 11;
|
||||
|
||||
/// `SOL_IP` / `SOL_UDP` when libc does not bind them. Linux takes the
|
||||
/// header names; Windows takes WinSock `SOL_IP`. Elsewhere they are the
|
||||
/// IANA protocol numbers.
|
||||
#[cfg(not(any(
|
||||
target_os = "android",
|
||||
target_os = "fuchsia",
|
||||
target_os = "linux",
|
||||
windows
|
||||
)))]
|
||||
pub const SOL_IP: i32 = 0;
|
||||
#[cfg(not(any(
|
||||
target_os = "android",
|
||||
target_os = "fuchsia",
|
||||
target_os = "linux",
|
||||
windows
|
||||
)))]
|
||||
pub const SOL_UDP: i32 = 17;
|
||||
|
||||
/// `SOMAXCONN` when neither libc nor WinSock publishes it.
|
||||
#[cfg(not(any(
|
||||
target_os = "android",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "fuchsia",
|
||||
target_os = "linux",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
target_vendor = "apple",
|
||||
windows
|
||||
)))]
|
||||
pub const SOMAXCONN: i32 = 5;
|
||||
|
||||
/// Bluetooth wildcard / local addresses. Header strings, not libc names.
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
target_os = "freebsd",
|
||||
target_os = "fuchsia",
|
||||
target_os = "linux",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
pub const BDADDR_ANY: &str = "00:00:00:00:00:00";
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
target_os = "freebsd",
|
||||
target_os = "fuchsia",
|
||||
target_os = "linux",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
pub const BDADDR_LOCAL: &str = "00:00:00:FF:FF:FF";
|
||||
|
||||
/// RFC 3542 IPv6 socket options (`netinet6/in6.h`). Not in libc.
|
||||
#[cfg(target_vendor = "apple")]
|
||||
pub const IPV6_RECVHOPLIMIT: i32 = 37;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
//! Socket constant surface for `wasm32-unknown-unknown` and WASI.
|
||||
//!
|
||||
//! There are no BSD sockets on unknown-unknown, and WASI does not use the
|
||||
//! unix/windows socket engine yet. The numbers are the Linux ABI
|
||||
//! `Lib/socket.py` expects so the stdlib can import.
|
||||
|
||||
pub const AF_UNSPEC: i32 = 0;
|
||||
pub const AF_UNIX: i32 = 1;
|
||||
pub const AF_INET: i32 = 2;
|
||||
pub const AF_INET6: i32 = 10;
|
||||
|
||||
pub const SOCK_STREAM: i32 = 1;
|
||||
pub const SOCK_DGRAM: i32 = 2;
|
||||
pub const SOCK_RAW: i32 = 3;
|
||||
|
||||
pub const SOL_SOCKET: i32 = 1;
|
||||
pub const SO_REUSEADDR: i32 = 2;
|
||||
pub const SO_TYPE: i32 = 3;
|
||||
pub const SO_ERROR: i32 = 4;
|
||||
pub const SO_BROADCAST: i32 = 6;
|
||||
pub const SO_KEEPALIVE: i32 = 9;
|
||||
pub const SO_RCVBUF: i32 = 8;
|
||||
pub const SO_SNDBUF: i32 = 7;
|
||||
|
||||
pub const IPPROTO_IP: i32 = 0;
|
||||
pub const IPPROTO_TCP: i32 = 6;
|
||||
pub const IPPROTO_UDP: i32 = 17;
|
||||
pub const IPPROTO_IPV6: i32 = 41;
|
||||
pub const SOL_TCP: i32 = IPPROTO_TCP;
|
||||
|
||||
pub const SHUT_RD: i32 = 0;
|
||||
pub const SHUT_WR: i32 = 1;
|
||||
pub const SHUT_RDWR: i32 = 2;
|
||||
|
||||
pub const MSG_OOB: i32 = 1;
|
||||
pub const MSG_PEEK: i32 = 2;
|
||||
pub const MSG_DONTROUTE: i32 = 4;
|
||||
|
||||
pub const AI_PASSIVE: i32 = 1;
|
||||
pub const AI_CANONNAME: i32 = 2;
|
||||
pub const AI_NUMERICHOST: i32 = 4;
|
||||
pub const AI_NUMERICSERV: i32 = 8;
|
||||
pub const AI_ADDRCONFIG: i32 = 32;
|
||||
|
||||
pub const NI_NUMERICHOST: i32 = 1;
|
||||
pub const NI_NUMERICSERV: i32 = 2;
|
||||
pub const NI_NOFQDN: i32 = 4;
|
||||
pub const NI_NAMEREQD: i32 = 8;
|
||||
pub const NI_DGRAM: i32 = 16;
|
||||
|
||||
pub const INADDR_ANY: u32 = 0;
|
||||
pub const INADDR_LOOPBACK: u32 = 0x7f00_0001;
|
||||
pub const INADDR_BROADCAST: u32 = 0xffff_ffff;
|
||||
pub const INADDR_NONE: u32 = 0xffff_ffff;
|
||||
pub const IPPORT_RESERVED: i32 = 1024;
|
||||
pub const IPPORT_USERRESERVED: i32 = 5000;
|
||||
pub const TCP_NODELAY: i32 = 1;
|
||||
@@ -65,10 +65,13 @@ mod suggestions;
|
||||
|
||||
// TODO: maybe make this an extension module, if we ever get those
|
||||
// mod re;
|
||||
#[cfg(all(feature = "host_env", not(target_arch = "wasm32")))]
|
||||
#[cfg(all(
|
||||
feature = "host_env",
|
||||
not(any(all(target_arch = "wasm32", target_os = "unknown"), target_os = "wasi"))
|
||||
))]
|
||||
pub mod socket;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(any(all(target_arch = "wasm32", target_os = "unknown"), target_os = "wasi"))]
|
||||
#[path = "socket_wasm.rs"]
|
||||
pub mod socket;
|
||||
|
||||
@@ -267,9 +270,12 @@ pub fn stdlib_module_defs(ctx: &Context) -> Vec<&'static builtins::PyModuleDef>
|
||||
sha256::module_def(ctx),
|
||||
sha3::module_def(ctx),
|
||||
sha512::module_def(ctx),
|
||||
#[cfg(all(feature = "host_env", not(target_arch = "wasm32")))]
|
||||
#[cfg(all(
|
||||
feature = "host_env",
|
||||
not(any(all(target_arch = "wasm32", target_os = "unknown"), target_os = "wasi"))
|
||||
))]
|
||||
socket::module_def(ctx),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(any(all(target_arch = "wasm32", target_os = "unknown"), target_os = "wasi"))]
|
||||
socket::module_def(ctx),
|
||||
#[cfg(all(
|
||||
feature = "sqlite",
|
||||
|
||||
@@ -136,62 +136,27 @@ mod _ssl {
|
||||
X509_V_FLAG_X509_STRICT as VERIFY_X509_STRICT,
|
||||
};
|
||||
|
||||
// SSL Alert Descriptions (RFC 5246 and extensions)
|
||||
// Hybrid approach: use openssl_sys constants where available, hardcode others
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_CLOSE_NOTIFY: core::ffi::c_int = 0;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: core::ffi::c_int = 10;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_BAD_RECORD_MAC: core::ffi::c_int = 20;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_RECORD_OVERFLOW: core::ffi::c_int = 22;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: core::ffi::c_int = 30;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_HANDSHAKE_FAILURE: core::ffi::c_int = 40;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_BAD_CERTIFICATE: core::ffi::c_int = 42;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: core::ffi::c_int = 43;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_CERTIFICATE_REVOKED: core::ffi::c_int = 44;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: core::ffi::c_int = 45;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: core::ffi::c_int = 46;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_ILLEGAL_PARAMETER: core::ffi::c_int = SSL_AD_ILLEGAL_PARAMETER;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_UNKNOWN_CA: core::ffi::c_int = 48;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_ACCESS_DENIED: core::ffi::c_int = 49;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_DECODE_ERROR: core::ffi::c_int = SSL_AD_DECODE_ERROR;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_DECRYPT_ERROR: core::ffi::c_int = 51;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_PROTOCOL_VERSION: core::ffi::c_int = 70;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: core::ffi::c_int = 71;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_INTERNAL_ERROR: core::ffi::c_int = 80;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_USER_CANCELLED: core::ffi::c_int = 90;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_NO_RENEGOTIATION: core::ffi::c_int = 100;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: core::ffi::c_int = 110;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: core::ffi::c_int = 111;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_UNRECOGNIZED_NAME: core::ffi::c_int = SSL_AD_UNRECOGNIZED_NAME;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: core::ffi::c_int = 113;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: core::ffi::c_int = 114;
|
||||
#[pyattr]
|
||||
const ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: core::ffi::c_int = 115;
|
||||
use rustpython_host_env::ssl::{
|
||||
ALERT_DESCRIPTION_ACCESS_DENIED, ALERT_DESCRIPTION_BAD_CERTIFICATE,
|
||||
ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE,
|
||||
ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE, ALERT_DESCRIPTION_BAD_RECORD_MAC,
|
||||
ALERT_DESCRIPTION_CERTIFICATE_EXPIRED, ALERT_DESCRIPTION_CERTIFICATE_REQUIRED,
|
||||
ALERT_DESCRIPTION_CERTIFICATE_REVOKED, ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN,
|
||||
ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE, ALERT_DESCRIPTION_CLOSE_NOTIFY,
|
||||
ALERT_DESCRIPTION_DECODE_ERROR, ALERT_DESCRIPTION_DECOMPRESSION_FAILURE,
|
||||
ALERT_DESCRIPTION_DECRYPT_ERROR, ALERT_DESCRIPTION_DECRYPTION_FAILED,
|
||||
ALERT_DESCRIPTION_EXPORT_RESTRICTION, ALERT_DESCRIPTION_HANDSHAKE_FAILURE,
|
||||
ALERT_DESCRIPTION_ILLEGAL_PARAMETER, ALERT_DESCRIPTION_INAPPROPRIATE_FALLBACK,
|
||||
ALERT_DESCRIPTION_INSUFFICIENT_SECURITY, ALERT_DESCRIPTION_INTERNAL_ERROR,
|
||||
ALERT_DESCRIPTION_MISSING_EXTENSION, ALERT_DESCRIPTION_NO_APPLICATION_PROTOCOL,
|
||||
ALERT_DESCRIPTION_NO_CERTIFICATE, ALERT_DESCRIPTION_NO_RENEGOTIATION,
|
||||
ALERT_DESCRIPTION_PROTOCOL_VERSION, ALERT_DESCRIPTION_RECORD_OVERFLOW,
|
||||
ALERT_DESCRIPTION_UNEXPECTED_MESSAGE, ALERT_DESCRIPTION_UNKNOWN_CA,
|
||||
ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY, ALERT_DESCRIPTION_UNRECOGNIZED_NAME,
|
||||
ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE, ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION,
|
||||
ALERT_DESCRIPTION_USER_CANCELLED,
|
||||
};
|
||||
|
||||
// CRL verification constants
|
||||
#[pyattr]
|
||||
|
||||
@@ -262,40 +262,12 @@ mod _socket {
|
||||
TCP_SYNCNT, TCP_WINDOW_CLAMP,
|
||||
};
|
||||
|
||||
// gated on presence of AF_VSOCK:
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
const SO_VM_SOCKETS_BUFFER_SIZE: u32 = 0;
|
||||
|
||||
// gated on presence of AF_VSOCK:
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
const SO_VM_SOCKETS_BUFFER_MIN_SIZE: u32 = 1;
|
||||
|
||||
// gated on presence of AF_VSOCK:
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
const SO_VM_SOCKETS_BUFFER_MAX_SIZE: u32 = 2;
|
||||
|
||||
// gated on presence of AF_VSOCK:
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
const VMADDR_CID_ANY: u32 = 0xffffffff; // 0xffffffff
|
||||
|
||||
// gated on presence of AF_VSOCK:
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
const VMADDR_PORT_ANY: u32 = 0xffffffff; // 0xffffffff
|
||||
|
||||
// gated on presence of AF_VSOCK:
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
const VMADDR_CID_HOST: u32 = 2;
|
||||
|
||||
// gated on presence of AF_VSOCK:
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
const VM_SOCKETS_INVALID_VERSION: u32 = 0xffffffff; // 0xffffffff
|
||||
use host_socket::{
|
||||
SO_VM_SOCKETS_BUFFER_MAX_SIZE, SO_VM_SOCKETS_BUFFER_MIN_SIZE, SO_VM_SOCKETS_BUFFER_SIZE,
|
||||
VM_SOCKETS_INVALID_VERSION, VMADDR_CID_ANY, VMADDR_CID_HOST, VMADDR_PORT_ANY,
|
||||
};
|
||||
|
||||
// TODO: gated on https://github.com/rust-lang/libc/pull/1662
|
||||
// // gated on presence of AF_VSOCK:
|
||||
@@ -307,11 +279,7 @@ mod _socket {
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "fuchsia", target_os = "linux")))]
|
||||
#[pyattr]
|
||||
const SOL_IP: i32 = 0;
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "fuchsia", target_os = "linux")))]
|
||||
#[pyattr]
|
||||
const SOL_UDP: i32 = 17;
|
||||
use host_socket::{SOL_IP, SOL_UDP};
|
||||
|
||||
#[cfg(any(target_os = "android", target_os = "linux", windows))]
|
||||
#[pyattr]
|
||||
@@ -345,16 +313,7 @@ mod _socket {
|
||||
target_os = "linux"
|
||||
))]
|
||||
#[pyattr]
|
||||
const UDPLITE_SEND_CSCOV: i32 = 10;
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
target_os = "fuchsia",
|
||||
target_os = "freebsd",
|
||||
target_os = "linux"
|
||||
))]
|
||||
#[pyattr]
|
||||
const UDPLITE_RECV_CSCOV: i32 = 11;
|
||||
use host_socket::{UDPLITE_RECV_CSCOV, UDPLITE_SEND_CSCOV};
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
@@ -693,7 +652,7 @@ mod _socket {
|
||||
windows
|
||||
)))]
|
||||
#[pyattr]
|
||||
const SOMAXCONN: i32 = 5; // Common value
|
||||
use host_socket::SOMAXCONN;
|
||||
|
||||
// HERE IS WHERE THE BLUETOOTH CONSTANTS START
|
||||
// TODO: there should be a more intelligent way of detecting bluetooth on a platform.
|
||||
@@ -716,16 +675,7 @@ mod _socket {
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
#[pyattr]
|
||||
const BDADDR_ANY: &str = "00:00:00:00:00:00";
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
target_os = "freebsd",
|
||||
target_os = "fuchsia",
|
||||
target_os = "linux",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
#[pyattr]
|
||||
const BDADDR_LOCAL: &str = "00:00:00:FF:FF:FF";
|
||||
use host_socket::{BDADDR_ANY, BDADDR_LOCAL};
|
||||
// HERE IS WHERE THE BLUETOOTH CONSTANTS END
|
||||
|
||||
#[cfg(windows)]
|
||||
|
||||
@@ -20,99 +20,15 @@ mod _socket {
|
||||
use std::sync::atomic::{AtomicI32, AtomicU64, Ordering};
|
||||
|
||||
#[pyattr]
|
||||
const AF_UNSPEC: i32 = 0;
|
||||
#[pyattr]
|
||||
const AF_UNIX: i32 = 1;
|
||||
#[pyattr]
|
||||
const AF_INET: i32 = 2;
|
||||
#[pyattr]
|
||||
const AF_INET6: i32 = 10;
|
||||
|
||||
#[pyattr]
|
||||
const SOCK_STREAM: i32 = 1;
|
||||
#[pyattr]
|
||||
const SOCK_DGRAM: i32 = 2;
|
||||
#[pyattr]
|
||||
const SOCK_RAW: i32 = 3;
|
||||
|
||||
#[pyattr]
|
||||
const SOL_SOCKET: i32 = 1;
|
||||
#[pyattr]
|
||||
const SO_REUSEADDR: i32 = 2;
|
||||
#[pyattr]
|
||||
const SO_TYPE: i32 = 3;
|
||||
#[pyattr]
|
||||
const SO_ERROR: i32 = 4;
|
||||
#[pyattr]
|
||||
const SO_BROADCAST: i32 = 6;
|
||||
#[pyattr]
|
||||
const SO_KEEPALIVE: i32 = 9;
|
||||
#[pyattr]
|
||||
const SO_RCVBUF: i32 = 8;
|
||||
#[pyattr]
|
||||
const SO_SNDBUF: i32 = 7;
|
||||
|
||||
#[pyattr]
|
||||
const IPPROTO_IP: i32 = 0;
|
||||
#[pyattr]
|
||||
const IPPROTO_TCP: i32 = 6;
|
||||
#[pyattr]
|
||||
const IPPROTO_UDP: i32 = 17;
|
||||
#[pyattr]
|
||||
const IPPROTO_IPV6: i32 = 41;
|
||||
#[pyattr]
|
||||
const SOL_TCP: i32 = IPPROTO_TCP;
|
||||
|
||||
#[pyattr]
|
||||
const SHUT_RD: i32 = 0;
|
||||
#[pyattr]
|
||||
const SHUT_WR: i32 = 1;
|
||||
#[pyattr]
|
||||
const SHUT_RDWR: i32 = 2;
|
||||
|
||||
#[pyattr]
|
||||
const MSG_OOB: i32 = 1;
|
||||
#[pyattr]
|
||||
const MSG_PEEK: i32 = 2;
|
||||
#[pyattr]
|
||||
const MSG_DONTROUTE: i32 = 4;
|
||||
|
||||
#[pyattr]
|
||||
const AI_PASSIVE: i32 = 1;
|
||||
#[pyattr]
|
||||
const AI_CANONNAME: i32 = 2;
|
||||
#[pyattr]
|
||||
const AI_NUMERICHOST: i32 = 4;
|
||||
#[pyattr]
|
||||
const AI_NUMERICSERV: i32 = 8;
|
||||
#[pyattr]
|
||||
const AI_ADDRCONFIG: i32 = 32;
|
||||
|
||||
#[pyattr]
|
||||
const NI_NUMERICHOST: i32 = 1;
|
||||
#[pyattr]
|
||||
const NI_NUMERICSERV: i32 = 2;
|
||||
#[pyattr]
|
||||
const NI_NOFQDN: i32 = 4;
|
||||
#[pyattr]
|
||||
const NI_NAMEREQD: i32 = 8;
|
||||
#[pyattr]
|
||||
const NI_DGRAM: i32 = 16;
|
||||
|
||||
#[pyattr]
|
||||
const INADDR_ANY: u32 = 0;
|
||||
#[pyattr]
|
||||
const INADDR_LOOPBACK: u32 = 0x7f00_0001;
|
||||
#[pyattr]
|
||||
const INADDR_BROADCAST: u32 = 0xffff_ffff;
|
||||
#[pyattr]
|
||||
const INADDR_NONE: u32 = 0xffff_ffff;
|
||||
#[pyattr]
|
||||
const IPPORT_RESERVED: i32 = 1024;
|
||||
#[pyattr]
|
||||
const IPPORT_USERRESERVED: i32 = 5000;
|
||||
#[pyattr]
|
||||
const TCP_NODELAY: i32 = 1;
|
||||
use rustpython_host_env::socket::{
|
||||
AF_INET, AF_INET6, AF_UNIX, AF_UNSPEC, AI_ADDRCONFIG, AI_CANONNAME, AI_NUMERICHOST,
|
||||
AI_NUMERICSERV, AI_PASSIVE, INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_NONE,
|
||||
IPPORT_RESERVED, IPPORT_USERRESERVED, IPPROTO_IP, IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_UDP,
|
||||
MSG_DONTROUTE, MSG_OOB, MSG_PEEK, NI_DGRAM, NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST,
|
||||
NI_NUMERICSERV, SHUT_RD, SHUT_RDWR, SHUT_WR, SO_BROADCAST, SO_ERROR, SO_KEEPALIVE,
|
||||
SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SO_TYPE, SOCK_DGRAM, SOCK_RAW, SOCK_STREAM, SOL_SOCKET,
|
||||
SOL_TCP, TCP_NODELAY,
|
||||
};
|
||||
#[pyattr(name = "has_ipv6")]
|
||||
const HAS_IPV6: bool = true;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ cfg_select! {
|
||||
_ => {
|
||||
type Offset = i64;
|
||||
// EAGAIN constant for BlockingIOError
|
||||
const EAGAIN: i32 = 11; // Standard POSIX value
|
||||
const EAGAIN: i32 = rustpython_host_env::errno::errors::EAGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,20 +84,13 @@ mod _stat {
|
||||
);
|
||||
|
||||
#[pyattr]
|
||||
pub const S_IFDOOR: Mode = 0; // TODO: RUSTPYTHON Support Solaris
|
||||
pub const S_IFDOOR: Mode = rustpython_host_env::os::S_IFDOOR as Mode;
|
||||
|
||||
#[pyattr]
|
||||
pub const S_IFPORT: Mode = 0; // TODO: RUSTPYTHON Support Solaris
|
||||
|
||||
// TODO: RUSTPYTHON Support BSD
|
||||
// https://man.freebsd.org/cgi/man.cgi?stat(2)
|
||||
pub const S_IFPORT: Mode = rustpython_host_env::os::S_IFPORT as Mode;
|
||||
|
||||
#[pyattr]
|
||||
pub const S_IFWHT: Mode = if cfg!(target_os = "macos") {
|
||||
0o160000
|
||||
} else {
|
||||
0
|
||||
};
|
||||
pub const S_IFWHT: Mode = rustpython_host_env::os::S_IFWHT as Mode;
|
||||
|
||||
// Permission bits
|
||||
|
||||
@@ -255,73 +248,11 @@ mod _stat {
|
||||
|
||||
// Unix file flags (if on Unix)
|
||||
|
||||
#[pyattr]
|
||||
pub const UF_NODUMP: u32 = libc_const!(
|
||||
#[cfg(target_os = "macos")]
|
||||
UF_NODUMP,
|
||||
0x00000001
|
||||
);
|
||||
|
||||
#[pyattr]
|
||||
pub const UF_IMMUTABLE: u32 = libc_const!(
|
||||
#[cfg(target_os = "macos")]
|
||||
UF_IMMUTABLE,
|
||||
0x00000002
|
||||
);
|
||||
|
||||
#[pyattr]
|
||||
pub const UF_APPEND: u32 = libc_const!(
|
||||
#[cfg(target_os = "macos")]
|
||||
UF_APPEND,
|
||||
0x00000004
|
||||
);
|
||||
|
||||
#[pyattr]
|
||||
pub const UF_OPAQUE: u32 = libc_const!(
|
||||
#[cfg(target_os = "macos")]
|
||||
UF_OPAQUE,
|
||||
0x00000008
|
||||
);
|
||||
|
||||
#[pyattr]
|
||||
pub const UF_COMPRESSED: u32 = libc_const!(
|
||||
#[cfg(target_os = "macos")]
|
||||
UF_COMPRESSED,
|
||||
0x00000020
|
||||
);
|
||||
|
||||
#[pyattr]
|
||||
pub const UF_HIDDEN: u32 = libc_const!(
|
||||
#[cfg(target_os = "macos")]
|
||||
UF_HIDDEN,
|
||||
0x00008000
|
||||
);
|
||||
|
||||
#[pyattr]
|
||||
pub const SF_ARCHIVED: u32 = libc_const!(
|
||||
#[cfg(target_os = "macos")]
|
||||
SF_ARCHIVED,
|
||||
0x00010000
|
||||
);
|
||||
|
||||
#[pyattr]
|
||||
pub const SF_IMMUTABLE: u32 = libc_const!(
|
||||
#[cfg(target_os = "macos")]
|
||||
SF_IMMUTABLE,
|
||||
0x00020000
|
||||
);
|
||||
|
||||
#[pyattr]
|
||||
pub const SF_APPEND: u32 = libc_const!(
|
||||
#[cfg(target_os = "macos")]
|
||||
SF_APPEND,
|
||||
0x00040000
|
||||
);
|
||||
|
||||
#[pyattr]
|
||||
pub use rustpython_host_env::os::{
|
||||
SF_DATALESS, SF_FIRMLINK, SF_NOUNLINK, SF_SETTABLE, SF_SNAPSHOT, UF_DATAVAULT, UF_NOUNLINK,
|
||||
UF_SETTABLE, UF_TRACKED,
|
||||
SF_APPEND, SF_ARCHIVED, SF_DATALESS, SF_FIRMLINK, SF_IMMUTABLE, SF_NOUNLINK, SF_SETTABLE,
|
||||
SF_SNAPSHOT, UF_APPEND, UF_COMPRESSED, UF_DATAVAULT, UF_HIDDEN, UF_IMMUTABLE, UF_NODUMP,
|
||||
UF_NOUNLINK, UF_OPAQUE, UF_SETTABLE, UF_TRACKED,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
|
||||
@@ -23,15 +23,8 @@ mod errno_mod {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(unix, windows, target_os = "wasi"))]
|
||||
pub use rustpython_host_env::errno::errors;
|
||||
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
|
||||
pub mod errors {
|
||||
pub const ECONNABORTED: i32 = 103;
|
||||
pub const ECONNRESET: i32 = 104;
|
||||
}
|
||||
|
||||
#[cfg(any(unix, windows, target_os = "wasi"))]
|
||||
macro_rules! e {
|
||||
($name:ident) => {
|
||||
|
||||
Reference in new issue
Block a user