![]() |
LINE Solver (C++)
Templated C++ port of the LINE queueing solver
|
Classes | |
| struct | FileStat |
| What stat_file reports. More... | |
Typedefs | |
| typedef std::intptr_t | socket_t |
| A TCP socket: a POSIX descriptor or a Winsock SOCKET. | |
Enumerations | |
| enum class | ConnectFailure { None , Resolve , Connect } |
| Why tcp_connect failed, so the caller keeps its own wording. More... | |
Functions | |
| char | path_list_separator () |
| const char * | null_device () |
| const char * | exe_suffix () |
| std::string | temp_root () |
| TMPDIR, else /tmp. | |
| std::string | home_dir () |
| HOME, or empty. | |
| bool | is_regular_file (const std::string &p) |
| bool | is_directory (const std::string &p) |
| bool | is_executable (const std::string &p) |
| Exists and the caller may execute it (a directory with +x included, as access() says). | |
| bool | is_writable (const std::string &p) |
| bool | stat_file (const std::string &p, FileStat &out) |
| std::string | find_on_path (const std::string &name) |
| The first dir/name on PATH that is a regular executable file, or empty. | |
| std::string | self_exe_path () |
| This executable's path, or empty when it cannot be read. | |
| std::string | current_dir () |
| std::string | host_sysname () |
| uname -s, or empty. | |
| std::string | host_machine () |
| uname -m, or empty. | |
| bool | make_dir_or_exists (const std::string &path) |
| mkdir 0700; an existing entry is success. | |
| std::string | make_temp_dir (const std::string &tmpl) |
| mkdtemp on a template ending in XXXXXX; empty on failure. | |
| int | make_temp_file (std::string &tmpl) |
| mkstemp: replaces the XXXXXX in tmpl and returns an open descriptor, or -1. | |
| int | dup_fd (int fd) |
| int | dup2_fd (int from, int to) |
| POSIX dup2 returns the new descriptor; the CRT's _dup2 returns 0. | |
| int | close_fd (int fd) |
| bool | remove_file (const std::string &p) |
| bool | rename_replace (const std::string &from, const std::string &to) |
| void | remove_tree (const std::string &dir) |
| Remove a directory and everything under it, not following symlinks. | |
| long | process_id () |
| long long | free_disk_bytes (const std::string &path) |
| Bytes available to this user on the filesystem holding path; -1 if unknown. | |
| double | available_memory_bytes () |
| Available physical memory in bytes; negative when the host cannot say. | |
| long long | monotonic_millis () |
| Milliseconds on the monotonic clock, for deadlines that survive a clock step. | |
| void | sleep_millis (long millis) |
| bool | docker_user_spec (std::string &out) |
| "uid:gid" for docker run --user; false where the notion does not apply. | |
| bool | 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 | 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 | set_io_timeout (socket_t s, int millis) |
| Set the receive and send timeouts; not positive leaves them as they are. | |
| socket_t | 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 | tcp_listen_any (int port, int backlog, std::string &stage) |
| An IPv4 listener on every interface with SO_REUSEADDR. | |
| socket_t | tcp_accept (socket_t listener) |
| int | 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 | send_some (socket_t s, const char *p, std::size_t n) |
| send() without SIGPIPE; bytes sent or -1. | |
| long | recv_some (socket_t s, char *p, std::size_t n) |
| void | close_socket (socket_t s) |
| int | last_socket_error () |
| bool | err_interrupted (int e) |
| bool | err_timed_out (int e) |
| A Winsock receive timeout reports WSAETIMEDOUT where POSIX reports EAGAIN. | |
| std::string | socket_error_text (int e) |
Variables | |
| static const socket_t | kInvalidSocket = -1 |
| typedef std::intptr_t line::platform::socket_t |
A TCP socket: a POSIX descriptor or a Winsock SOCKET.
Definition at line 61 of file platform.h.
|
strong |
Why tcp_connect failed, so the caller keeps its own wording.
| Enumerator | |
|---|---|
| None | |
| Resolve | |
| Connect | |
Definition at line 73 of file platform.h.
|
inline |
Available physical memory in bytes; negative when the host cannot say.
Definition at line 277 of file platform.h.
References available_memory_bytes().
Referenced by available_memory_bytes(), and line::mc::ctmc_available_memory_bytes().
|
inline |
Definition at line 239 of file platform.h.
References close_fd().
Referenced by close_fd(), line::io::jsim_stage_stdin(), run_invocation(), and run_server().
|
inline |
Definition at line 522 of file platform.h.
References close_socket(), and kInvalidSocket.
Referenced by close_socket(), line::ws::Server::serve_one(), and line::ws::Server::~Server().
|
inline |
|
inline |
"uid:gid" for docker run --user; false where the notion does not apply.
Docker Desktop maps the caller itself; there is no uid:gid to pass.
Definition at line 302 of file platform.h.
References docker_user_spec().
Referenced by docker_user_spec(), and line::jmt::jmt_run_docker().
|
inline |
POSIX dup2 returns the new descriptor; the CRT's _dup2 returns 0.
Definition at line 238 of file platform.h.
References dup2_fd().
Referenced by dup2_fd(), and FdCapture::FdCapture().
|
inline |
Definition at line 237 of file platform.h.
References dup_fd().
Referenced by dup_fd(), and FdCapture::FdCapture().
|
inline |
Definition at line 527 of file platform.h.
References err_interrupted().
Referenced by err_interrupted().
|
inline |
A Winsock receive timeout reports WSAETIMEDOUT where POSIX reports EAGAIN.
Definition at line 528 of file platform.h.
References err_timed_out().
Referenced by err_timed_out().
|
inline |
|
inline |
The first dir/name on PATH that is a regular executable file, or empty.
The first dir/name on PATH that is a regular file, trying name.exe too when name carries no extension, as cmd.exe resolves a bare command.
Definition at line 174 of file platform.h.
References find_on_path(), and is_regular_file().
Referenced by line::io::tikz_detail::find_on_path(), find_on_path(), and line::io::wfcommons_detail::which_on_path().
|
inline |
Bytes available to this user on the filesystem holding path; -1 if unknown.
Definition at line 268 of file platform.h.
References free_disk_bytes().
Referenced by free_disk_bytes().
|
inline |
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").
Definition at line 481 of file platform.h.
References free_loopback_port().
Referenced by free_loopback_port().
|
inline |
HOME, or empty.
Definition at line 138 of file platform.h.
References home_dir().
Referenced by home_dir(), and line::util::make_temp_dir().
|
inline |
uname -m, or empty.
Definition at line 210 of file platform.h.
References host_machine().
Referenced by host_machine(), and line::mc::gate_detail::machine_signature().
|
inline |
uname -s, or empty.
Definition at line 204 of file platform.h.
References host_sysname().
Referenced by host_sysname(), and line::mc::gate_detail::machine_signature().
|
inline |
|
inline |
Exists and the caller may execute it (a directory with +x included, as access() says).
Windows has no execute bit: anything that exists may be run (or entered).
Definition at line 154 of file platform.h.
References is_executable().
Referenced by is_executable().
|
inline |
Definition at line 143 of file platform.h.
References is_regular_file().
Referenced by line::io::tikz_detail::file_exists(), find_on_path(), and is_regular_file().
|
inline |
|
inline |
Definition at line 526 of file platform.h.
References last_socket_error().
Referenced by last_socket_error().
|
inline |
mkdir 0700; an existing entry is success.
Definition at line 216 of file platform.h.
References make_dir_or_exists().
Referenced by make_dir_or_exists().
|
inline |
mkdtemp on a template ending in XXXXXX; empty on failure.
Definition at line 221 of file platform.h.
References make_temp_dir().
Referenced by make_temp_dir(), and line::util::make_temp_dir().
|
inline |
mkstemp: replaces the XXXXXX in tmpl and returns an open descriptor, or -1.
Definition at line 229 of file platform.h.
References make_temp_file().
Referenced by FdCapture::FdCapture(), line::io::jsim_stage_stdin(), make_temp_file(), run_invocation(), and run_server().
|
inline |
Milliseconds on the monotonic clock, for deadlines that survive a clock step.
Definition at line 288 of file platform.h.
References monotonic_millis().
Referenced by monotonic_millis().
|
inline |
|
inline |
Definition at line 127 of file platform.h.
References path_list_separator().
Referenced by path_list_separator().
|
inline |
Definition at line 265 of file platform.h.
References process_id().
Referenced by line::jmt::jmt_run_docker(), and process_id().
|
inline |
|
inline |
|
inline |
Remove a directory and everything under it, not following symlinks.
Remove a directory and everything under it.
A directory junction or symlink (a reparse point) is removed as an entry and NOT descended into, the Windows form of lstat's "do not follow". A read-only file is made writable first, since DeleteFile refuses it and unlink on POSIX would not care.
Definition at line 246 of file platform.h.
References remove_tree().
Referenced by remove_tree().
|
inline |
Definition at line 241 of file platform.h.
References rename_replace().
Referenced by rename_replace().
|
inline |
This executable's path, or empty when it cannot be read.
Definition at line 191 of file platform.h.
References self_exe_path().
Referenced by self_exe_path().
|
inline |
send() without SIGPIPE; bytes sent or -1.
Winsock raises no SIGPIPE, so a plain send() is the MSG_NOSIGNAL send.
Definition at line 509 of file platform.h.
References send_some().
Referenced by send_some().
|
inline |
Set the receive and send timeouts; not positive leaves them as they are.
Definition at line 397 of file platform.h.
References set_io_timeout().
Referenced by set_io_timeout().
|
inline |
|
inline |
Definition at line 529 of file platform.h.
References socket_error_text().
Referenced by socket_error_text().
|
inline |
Start argv detached (own session, std streams on /dev/null, double fork so no zombie).
Start argv detached from this console with no standard streams, the Windows form of the POSIX double fork.
Like the POSIX version, success means the process was started, not that the program it names did what was asked.
Definition at line 309 of file platform.h.
References spawn_detached().
Referenced by line::io::tikz_detail::spawn_detached(), and spawn_detached().
|
inline |
Definition at line 163 of file platform.h.
References line::platform::FileStat::is_dir, line::platform::FileStat::is_reg, line::platform::FileStat::mtime, line::platform::FileStat::size, and stat_file().
Referenced by line::jmt::jmt_version(), and stat_file().
Definition at line 472 of file platform.h.
References tcp_accept().
Referenced by line::ws::Server::serve_one(), and tcp_accept().
|
inline |
Connect with a deadline on the connect itself: each resolved address is tried non-blocking, then polled for writability, and SO_ERROR read back.
lastError is the reason the last address failed.
Definition at line 340 of file platform.h.
References Connect, kInvalidSocket, None, Resolve, and tcp_connect().
Referenced by tcp_connect().
|
inline |
Connect with the I/O timeouts set BEFORE a blocking connect, so they bound the connect as well (Linux honours SO_SNDTIMEO there).
The I/O timeouts are set first, as on POSIX.
port may be a service name; ioSeconds of zero leaves the socket unbounded.
Winsock does NOT bound a blocking connect by SO_SNDTIMEO the way Linux does, so the connect is made non-blocking under the same bound instead; zero leaves both unbounded.
Definition at line 412 of file platform.h.
References Connect, kInvalidSocket, None, Resolve, and tcp_connect_blocking().
Referenced by tcp_connect_blocking().
|
inline |
An IPv4 listener on every interface with SO_REUSEADDR.
No SO_REUSEADDR here, on purpose: on Windows it lets a second socket STEAL a port that is in active use, whereas the POSIX meaning (rebind past TIME_WAIT) is already Winsock's default.
On failure returns kInvalidSocket and names the step in stage ("socket", "bind" or "listen").
Definition at line 446 of file platform.h.
References kInvalidSocket, and tcp_listen_any().
Referenced by line::ws::Server::Server(), and tcp_listen_any().
|
inline |
TMPDIR, else /tmp.
Definition at line 132 of file platform.h.
References temp_root().
Referenced by line::mc::gate_detail::cache_file(), FdCapture::FdCapture(), line::io::jsim_stage_stdin(), line::util::make_temp_dir(), run_invocation(), run_server(), and temp_root().
|
static |
Definition at line 62 of file platform.h.
Referenced by close_socket(), tcp_connect(), tcp_connect_blocking(), and tcp_listen_any().