![]() |
LINE Solver (C++)
Templated C++ port of the LINE queueing solver
|
The operating-system services the engine uses, in one place. More...
#include <cstdint>#include <string>#include <vector>#include <cerrno>#include <cstdio>#include <cstdlib>#include <cstring>#include <ctime>#include <arpa/inet.h>#include <dirent.h>#include <fcntl.h>#include <netdb.h>#include <netinet/in.h>#include <poll.h>#include <sys/socket.h>#include <sys/stat.h>#include <sys/statvfs.h>#include <sys/time.h>#include <sys/types.h>#include <sys/utsname.h>#include <sys/wait.h>#include <unistd.h>Go to the source code of this file.
Classes | |
| struct | line::platform::FileStat |
| What stat_file reports. More... | |
Namespaces | |
| namespace | line |
| Conservation laws of a layered queueing network, enumerated from its structure. | |
| namespace | line::platform |
Typedefs | |
| typedef std::intptr_t | line::platform::socket_t |
| A TCP socket: a POSIX descriptor or a Winsock SOCKET. | |
Enumerations | |
| enum class | line::platform::ConnectFailure { line::platform::None , line::platform::Resolve , line::platform::Connect } |
| Why tcp_connect failed, so the caller keeps its own wording. More... | |
Functions | |
| char | line::platform::path_list_separator () |
| const char * | line::platform::null_device () |
| const char * | line::platform::exe_suffix () |
| std::string | line::platform::temp_root () |
| TMPDIR, else /tmp. | |
| std::string | line::platform::home_dir () |
| HOME, or empty. | |
| bool | line::platform::is_regular_file (const std::string &p) |
| bool | line::platform::is_directory (const std::string &p) |
| bool | line::platform::is_executable (const std::string &p) |
| Exists and the caller may execute it (a directory with +x included, as access() says). | |
| bool | line::platform::is_writable (const std::string &p) |
| bool | line::platform::stat_file (const std::string &p, FileStat &out) |
| std::string | line::platform::find_on_path (const std::string &name) |
| The first dir/name on PATH that is a regular executable file, or empty. | |
| std::string | line::platform::self_exe_path () |
| This executable's path, or empty when it cannot be read. | |
| std::string | line::platform::current_dir () |
| std::string | line::platform::host_sysname () |
| uname -s, or empty. | |
| std::string | line::platform::host_machine () |
| uname -m, or empty. | |
| bool | line::platform::make_dir_or_exists (const std::string &path) |
| mkdir 0700; an existing entry is success. | |
| std::string | line::platform::make_temp_dir (const std::string &tmpl) |
| mkdtemp on a template ending in XXXXXX; empty on failure. | |
| int | line::platform::make_temp_file (std::string &tmpl) |
| mkstemp: replaces the XXXXXX in tmpl and returns an open descriptor, or -1. | |
| int | line::platform::dup_fd (int fd) |
| int | line::platform::dup2_fd (int from, int to) |
| POSIX dup2 returns the new descriptor; the CRT's _dup2 returns 0. | |
| int | line::platform::close_fd (int fd) |
| bool | line::platform::remove_file (const std::string &p) |
| bool | line::platform::rename_replace (const std::string &from, const std::string &to) |
| void | line::platform::remove_tree (const std::string &dir) |
| Remove a directory and everything under it, not following symlinks. | |
| long | line::platform::process_id () |
| long long | line::platform::free_disk_bytes (const std::string &path) |
| Bytes available to this user on the filesystem holding path; -1 if unknown. | |
| double | line::platform::available_memory_bytes () |
| Available physical memory in bytes; negative when the host cannot say. | |
| long long | line::platform::monotonic_millis () |
| Milliseconds on the monotonic clock, for deadlines that survive a clock step. | |
| void | line::platform::sleep_millis (long millis) |
| bool | line::platform::docker_user_spec (std::string &out) |
| "uid:gid" for docker run --user; false where the notion does not apply. | |
| bool | line::platform::spawn_detached (const std::vector< std::string > &argv) |
| Start argv detached (own session, std streams on /dev/null, double fork so no zombie). | |
| socket_t | line::platform::tcp_connect (const std::string &host, int port, int connectMillis, ConnectFailure &why, std::string &lastError) |
| Connect with a deadline on the connect itself: each resolved address is tried non-blocking, then polled for writability, and SO_ERROR read back. | |
| void | line::platform::set_io_timeout (socket_t s, int millis) |
| Set the receive and send timeouts; not positive leaves them as they are. | |
| socket_t | line::platform::tcp_connect_blocking (const std::string &host, const std::string &port, double ioSeconds, ConnectFailure &why) |
| Connect with the I/O timeouts set BEFORE a blocking connect, so they bound the connect as well (Linux honours SO_SNDTIMEO there). | |
| socket_t | line::platform::tcp_listen_any (int port, int backlog, std::string &stage) |
| An IPv4 listener on every interface with SO_REUSEADDR. | |
| socket_t | line::platform::tcp_accept (socket_t listener) |
| int | line::platform::free_loopback_port (std::string &stage) |
| A loopback port the kernel reports free (bind port 0, read it back), or -1 with the failing step in stage ("socket", "bind" or "getsockname"). | |
| long | line::platform::send_some (socket_t s, const char *p, std::size_t n) |
| send() without SIGPIPE; bytes sent or -1. | |
| long | line::platform::recv_some (socket_t s, char *p, std::size_t n) |
| void | line::platform::close_socket (socket_t s) |
| int | line::platform::last_socket_error () |
| bool | line::platform::err_interrupted (int e) |
| bool | line::platform::err_timed_out (int e) |
| A Winsock receive timeout reports WSAETIMEDOUT where POSIX reports EAGAIN. | |
| std::string | line::platform::socket_error_text (int e) |
Variables | |
| static const socket_t | line::platform::kInvalidSocket = -1 |
The operating-system services the engine uses, in one place.
Every call that differs between POSIX and Windows goes through here: paths, the environment, files and directories, temporary files, process identity, host memory and disk, the monotonic clock and TCP sockets. The subprocess layer (subprocess.h) is the one other place that branches on the platform.
ON POSIX EVERYTHING IS INLINE AND IS THE CODE THE CALL SITES CARRIED BEFORE, moved rather than rewritten, so a Linux or macOS build behaves exactly as it did. ON WINDOWS THE SAME NAMES ARE ONLY DECLARED and are defined in src/util/platform_win.cpp (the line_mp_platform library, which line_mp links on WIN32 alone). That keeps <windows.h> and <winsock2.h> out of every header: their macros (min, max, ERROR, interface, ...) collide with names the engine uses, and a header-only library cannot contain them.
Sockets are carried as socket_t, an intptr_t that holds a POSIX descriptor or a Winsock SOCKET; kInvalidSocket is the failure value on both.
Definition in file platform.h.