LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
platform.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_UTIL_PLATFORM_H
6#define LINE_UTIL_PLATFORM_H
7
8/**
9 * @file
10 * @ingroup line_util
11 * The operating-system services the engine uses, in one place.
12 *
13 * Every call that differs between POSIX and Windows goes through here: paths,
14 * the environment, files and directories, temporary files, process identity,
15 * host memory and disk, the monotonic clock and TCP sockets. The subprocess
16 * layer (`subprocess.h`) is the one other place that branches on the platform.
17 *
18 * ON POSIX EVERYTHING IS INLINE AND IS THE CODE THE CALL SITES CARRIED BEFORE,
19 * moved rather than rewritten, so a Linux or macOS build behaves exactly as it
20 * did. ON WINDOWS THE SAME NAMES ARE ONLY DECLARED and are defined in
21 * `src/util/platform_win.cpp` (the `line_mp_platform` library, which `line_mp`
22 * links on WIN32 alone). That keeps `<windows.h>` and `<winsock2.h>` out of every
23 * header: their macros (`min`, `max`, `ERROR`, `interface`, ...) collide with
24 * names the engine uses, and a header-only library cannot contain them.
25 *
26 * Sockets are carried as `socket_t`, an intptr_t that holds a POSIX descriptor
27 * or a Winsock SOCKET; `kInvalidSocket` is the failure value on both.
28 */
29
30#include <cstdint>
31#include <string>
32#include <vector>
33
34#ifndef _WIN32
35#include <cerrno>
36#include <cstdio>
37#include <cstdlib>
38#include <cstring>
39#include <ctime>
40
41#include <arpa/inet.h>
42#include <dirent.h>
43#include <fcntl.h>
44#include <netdb.h>
45#include <netinet/in.h>
46#include <poll.h>
47#include <sys/socket.h>
48#include <sys/stat.h>
49#include <sys/statvfs.h>
50#include <sys/time.h>
51#include <sys/types.h>
52#include <sys/utsname.h>
53#include <sys/wait.h>
54#include <unistd.h>
55#endif
56
57namespace line {
58namespace platform {
59
60/** A TCP socket: a POSIX descriptor or a Winsock SOCKET. */
61typedef std::intptr_t socket_t;
62static const socket_t kInvalidSocket = -1;
63
64/** What `stat_file` reports. */
65struct FileStat {
66 long long size = 0; ///< bytes
67 long long mtime = 0; ///< seconds since the epoch
68 bool is_dir = false;
69 bool is_reg = false;
70};
71
72/** Why `tcp_connect` failed, so the caller keeps its own wording. */
73enum class ConnectFailure { None, Resolve, Connect };
74
75#ifdef _WIN32
76
78const char* null_device();
79const char* exe_suffix();
80std::string temp_root();
81std::string home_dir();
82bool is_regular_file(const std::string& p);
83bool is_directory(const std::string& p);
84bool is_executable(const std::string& p);
85bool is_writable(const std::string& p);
86bool stat_file(const std::string& p, FileStat& out);
87std::string find_on_path(const std::string& name);
88std::string self_exe_path();
89std::string current_dir();
90std::string host_sysname();
91std::string host_machine();
92bool make_dir_or_exists(const std::string& path);
93std::string make_temp_dir(const std::string& tmpl);
94int make_temp_file(std::string& tmpl);
95int dup_fd(int fd);
96int dup2_fd(int from, int to);
97int close_fd(int fd);
98bool remove_file(const std::string& p);
99bool rename_replace(const std::string& from, const std::string& to);
100void remove_tree(const std::string& dir);
101long process_id();
102long long free_disk_bytes(const std::string& path);
104long long monotonic_millis();
105void sleep_millis(long millis);
106bool docker_user_spec(std::string& out);
107bool spawn_detached(const std::vector<std::string>& argv);
108
109socket_t tcp_connect(const std::string& host, int port, int connectMillis,
110 ConnectFailure& why, std::string& lastError);
111socket_t tcp_connect_blocking(const std::string& host, const std::string& port,
112 double ioSeconds, ConnectFailure& why);
113socket_t tcp_listen_any(int port, int backlog, std::string& stage);
115int free_loopback_port(std::string& stage);
116void set_io_timeout(socket_t s, int millis);
117long send_some(socket_t s, const char* p, std::size_t n);
118long recv_some(socket_t s, char* p, std::size_t n);
119void close_socket(socket_t s);
121bool err_interrupted(int e);
122bool err_timed_out(int e);
123std::string socket_error_text(int e);
124
125#else // POSIX
126
127inline char path_list_separator() { return ':'; }
128inline const char* null_device() { return "/dev/null"; }
129inline const char* exe_suffix() { return ""; }
130
131/** TMPDIR, else /tmp. */
132inline std::string temp_root() {
133 const char* base = std::getenv("TMPDIR");
134 return (base && *base) ? std::string(base) : std::string("/tmp");
135}
136
137/** HOME, or empty. */
138inline std::string home_dir() {
139 const char* h = std::getenv("HOME");
140 return (h != nullptr && *h) ? std::string(h) : std::string();
141}
142
143inline bool is_regular_file(const std::string& p) {
144 struct stat st;
145 return !p.empty() && ::stat(p.c_str(), &st) == 0 && S_ISREG(st.st_mode);
146}
147
148inline bool is_directory(const std::string& p) {
149 struct stat st;
150 return !p.empty() && ::stat(p.c_str(), &st) == 0 && S_ISDIR(st.st_mode);
151}
152
153/** Exists and the caller may execute it (a directory with +x included, as access() says). */
154inline bool is_executable(const std::string& p) {
155 struct stat st;
156 return !p.empty() && ::stat(p.c_str(), &st) == 0 && ::access(p.c_str(), X_OK) == 0;
157}
158
159inline bool is_writable(const std::string& p) {
160 return !p.empty() && ::access(p.c_str(), W_OK) == 0;
161}
162
163inline bool stat_file(const std::string& p, FileStat& out) {
164 struct stat st;
165 if (p.empty() || ::stat(p.c_str(), &st) != 0) return false;
166 out.size = static_cast<long long>(st.st_size);
167 out.mtime = static_cast<long long>(st.st_mtime);
168 out.is_dir = S_ISDIR(st.st_mode);
169 out.is_reg = S_ISREG(st.st_mode);
170 return true;
171}
172
173/** The first `dir/name` on PATH that is a regular executable file, or empty. */
174inline std::string find_on_path(const std::string& name) {
175 const char* raw = std::getenv("PATH");
176 if (raw == nullptr) return std::string();
177 const std::string path(raw);
178 std::size_t b = 0;
179 while (b <= path.size()) {
180 const std::size_t e = path.find(':', b);
181 const std::string dir = path.substr(b, e == std::string::npos ? std::string::npos : e - b);
182 const std::string f = (dir.empty() ? std::string(".") : dir) + "/" + name;
183 if (is_regular_file(f) && ::access(f.c_str(), X_OK) == 0) return f;
184 if (e == std::string::npos) break;
185 b = e + 1;
186 }
187 return std::string();
188}
189
190/** This executable's path, or empty when it cannot be read. */
191inline std::string self_exe_path() {
192 char buf[4096];
193 const ssize_t n = ::readlink("/proc/self/exe", buf, sizeof(buf) - 1);
194 if (n <= 0) return std::string();
195 return std::string(buf, static_cast<std::size_t>(n));
196}
197
198inline std::string current_dir() {
199 char buf[4096];
200 return ::getcwd(buf, sizeof(buf)) != nullptr ? std::string(buf) : std::string();
201}
202
203/** `uname -s`, or empty. */
204inline std::string host_sysname() {
205 struct utsname u;
206 return ::uname(&u) == 0 ? std::string(u.sysname) : std::string();
207}
208
209/** `uname -m`, or empty. */
210inline std::string host_machine() {
211 struct utsname u;
212 return ::uname(&u) == 0 ? std::string(u.machine) : std::string();
213}
214
215/** mkdir 0700; an existing entry is success. */
216inline bool make_dir_or_exists(const std::string& path) {
217 return ::mkdir(path.c_str(), 0700) == 0 || errno == EEXIST;
218}
219
220/** mkdtemp on a template ending in XXXXXX; empty on failure. */
221inline std::string make_temp_dir(const std::string& tmpl) {
222 std::vector<char> buf(tmpl.begin(), tmpl.end());
223 buf.push_back('\0');
224 if (::mkdtemp(&buf[0]) == nullptr) return std::string();
225 return std::string(&buf[0]);
226}
227
228/** mkstemp: replaces the XXXXXX in `tmpl` and returns an open descriptor, or -1. */
229inline int make_temp_file(std::string& tmpl) {
230 std::vector<char> buf(tmpl.begin(), tmpl.end());
231 buf.push_back('\0');
232 const int fd = ::mkstemp(&buf[0]);
233 if (fd >= 0) tmpl.assign(&buf[0]);
234 return fd;
235}
236
237inline int dup_fd(int fd) { return ::dup(fd); }
238inline int dup2_fd(int from, int to) { return ::dup2(from, to); }
239inline int close_fd(int fd) { return ::close(fd); }
240inline bool remove_file(const std::string& p) { return ::unlink(p.c_str()) == 0; }
241inline bool rename_replace(const std::string& from, const std::string& to) {
242 return ::rename(from.c_str(), to.c_str()) == 0;
243}
244
245/** Remove a directory and everything under it, not following symlinks. */
246inline void remove_tree(const std::string& dir) {
247 DIR* d = ::opendir(dir.c_str());
248 if (d != nullptr) {
249 struct dirent* e;
250 while ((e = ::readdir(d)) != nullptr) {
251 const std::string n(e->d_name);
252 if (n == "." || n == "..") continue;
253 const std::string child = dir + "/" + n;
254 struct stat st;
255 if (::lstat(child.c_str(), &st) == 0 && S_ISDIR(st.st_mode))
256 remove_tree(child);
257 else
258 ::unlink(child.c_str());
259 }
260 ::closedir(d);
261 }
262 ::rmdir(dir.c_str());
263}
264
265inline long process_id() { return static_cast<long>(::getpid()); }
266
267/** Bytes available to this user on the filesystem holding `path`; -1 if unknown. */
268inline long long free_disk_bytes(const std::string& path) {
269 struct statvfs vfs;
270 if (::statvfs(path.c_str(), &vfs) != 0) return -1;
271 const long long usable =
272 static_cast<long long>(vfs.f_bavail) * static_cast<long long>(vfs.f_frsize);
273 return usable > 0 ? usable : -1;
274}
275
276/** Available physical memory in bytes; negative when the host cannot say. */
277inline double available_memory_bytes() {
278#if defined(_SC_AVPHYS_PAGES) && defined(_SC_PAGE_SIZE)
279 const long pages = ::sysconf(_SC_AVPHYS_PAGES);
280 const long page_size = ::sysconf(_SC_PAGE_SIZE);
281 if (pages > 0 && page_size > 0)
282 return static_cast<double>(pages) * static_cast<double>(page_size);
283#endif
284 return -1.0;
285}
286
287/** Milliseconds on the monotonic clock, for deadlines that survive a clock step. */
288inline long long monotonic_millis() {
289 struct timespec ts;
290 clock_gettime(CLOCK_MONOTONIC, &ts);
291 return static_cast<long long>(ts.tv_sec) * 1000LL + ts.tv_nsec / 1000000L;
292}
293
294inline void sleep_millis(long millis) {
295 struct timespec ts;
296 ts.tv_sec = millis / 1000;
297 ts.tv_nsec = (millis % 1000) * 1000000L;
298 ::nanosleep(&ts, nullptr);
299}
300
301/** "uid:gid" for `docker run --user`; false where the notion does not apply. */
302inline bool docker_user_spec(std::string& out) {
303 out = std::to_string(static_cast<unsigned long>(::getuid())) + ":" +
304 std::to_string(static_cast<unsigned long>(::getgid()));
305 return true;
306}
307
308/** Start `argv` detached (own session, std streams on /dev/null, double fork so no zombie). */
309inline bool spawn_detached(const std::vector<std::string>& argv) {
310 if (argv.empty()) return false;
311 const pid_t pid = ::fork();
312 if (pid < 0) return false;
313 if (pid == 0) {
314 ::setsid();
315 if (::fork() != 0) ::_exit(0);
316 const int devnull = ::open("/dev/null", O_RDWR);
317 if (devnull >= 0) {
318 ::dup2(devnull, STDIN_FILENO);
319 ::dup2(devnull, STDOUT_FILENO);
320 ::dup2(devnull, STDERR_FILENO);
321 if (devnull > STDERR_FILENO) ::close(devnull);
322 }
323 std::vector<char*> raw;
324 for (std::size_t i = 0; i < argv.size(); ++i)
325 raw.push_back(const_cast<char*>(argv[i].c_str()));
326 raw.push_back(nullptr);
327 ::execvp(raw[0], &raw[0]);
328 ::_exit(127);
329 }
330 int status = 0;
331 ::waitpid(pid, &status, 0);
332 return WIFEXITED(status) && WEXITSTATUS(status) == 0;
333}
334
335/**
336 * Connect with a deadline on the connect itself: each resolved address is tried
337 * non-blocking, then polled for writability, and SO_ERROR read back.
338 * `lastError` is the reason the last address failed.
339 */
340inline socket_t tcp_connect(const std::string& host, int port, int connectMillis,
341 ConnectFailure& why, std::string& lastError) {
343 struct addrinfo hints;
344 std::memset(&hints, 0, sizeof(hints));
345 hints.ai_family = AF_UNSPEC;
346 hints.ai_socktype = SOCK_STREAM;
347 struct addrinfo* res = nullptr;
348 const std::string portStr = std::to_string(port);
349 if (::getaddrinfo(host.c_str(), portStr.c_str(), &hints, &res) != 0 || res == nullptr) {
351 return kInvalidSocket;
352 }
353 int fd = -1;
354 lastError = "connection refused";
355 for (struct addrinfo* ai = res; ai != nullptr; ai = ai->ai_next) {
356 fd = ::socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
357 if (fd < 0) continue;
358 const int flags = ::fcntl(fd, F_GETFL, 0);
359 ::fcntl(fd, F_SETFL, flags | O_NONBLOCK);
360 int rc = ::connect(fd, ai->ai_addr, ai->ai_addrlen);
361 if (rc != 0 && errno == EINPROGRESS) {
362 struct pollfd pfd;
363 pfd.fd = fd;
364 pfd.events = POLLOUT;
365 pfd.revents = 0;
366 const int pr = ::poll(&pfd, 1, connectMillis > 0 ? connectMillis : -1);
367 if (pr > 0) {
368 int soerr = 0;
369 socklen_t len = sizeof(soerr);
370 if (::getsockopt(fd, SOL_SOCKET, SO_ERROR, &soerr, &len) == 0 && soerr == 0)
371 rc = 0;
372 else
373 lastError = std::strerror(soerr);
374 } else if (pr == 0) {
375 lastError = "connect timed out";
376 rc = -1;
377 } else {
378 lastError = std::strerror(errno);
379 rc = -1;
380 }
381 } else if (rc != 0) {
382 lastError = std::strerror(errno);
383 }
384 if (rc == 0) {
385 ::fcntl(fd, F_SETFL, flags);
386 break;
387 }
388 ::close(fd);
389 fd = -1;
390 }
391 ::freeaddrinfo(res);
392 if (fd < 0) why = ConnectFailure::Connect;
393 return fd < 0 ? kInvalidSocket : static_cast<socket_t>(fd);
394}
395
396/** Set the receive and send timeouts; not positive leaves them as they are. */
397inline void set_io_timeout(socket_t s, int millis) {
398 if (millis <= 0) return;
399 struct timeval tv;
400 tv.tv_sec = millis / 1000;
401 tv.tv_usec = (millis % 1000) * 1000;
402 const int fd = static_cast<int>(s);
403 ::setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
404 ::setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
405}
406
407/**
408 * Connect with the I/O timeouts set BEFORE a blocking connect, so they bound the
409 * connect as well (Linux honours SO_SNDTIMEO there). `port` may be a service
410 * name; `ioSeconds` of zero leaves the socket unbounded.
411 */
412inline socket_t tcp_connect_blocking(const std::string& host, const std::string& port,
413 double ioSeconds, ConnectFailure& why) {
415 struct addrinfo hints;
416 std::memset(&hints, 0, sizeof(hints));
417 hints.ai_family = AF_UNSPEC;
418 hints.ai_socktype = SOCK_STREAM;
419 struct addrinfo* res = nullptr;
420 if (::getaddrinfo(host.c_str(), port.c_str(), &hints, &res) != 0 || res == nullptr) {
422 return kInvalidSocket;
423 }
424 int fd = -1;
425 for (struct addrinfo* ai = res; ai != nullptr; ai = ai->ai_next) {
426 fd = ::socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
427 if (fd < 0) continue;
428 struct timeval tv;
429 tv.tv_sec = static_cast<long>(ioSeconds);
430 tv.tv_usec = static_cast<long>((ioSeconds - static_cast<double>(tv.tv_sec)) * 1e6);
431 ::setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
432 ::setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
433 if (::connect(fd, ai->ai_addr, ai->ai_addrlen) == 0) break;
434 ::close(fd);
435 fd = -1;
436 }
437 ::freeaddrinfo(res);
438 if (fd < 0) why = ConnectFailure::Connect;
439 return fd < 0 ? kInvalidSocket : static_cast<socket_t>(fd);
440}
441
442/**
443 * An IPv4 listener on every interface with SO_REUSEADDR. On failure returns
444 * kInvalidSocket and names the step in `stage` ("socket", "bind" or "listen").
445 */
446inline socket_t tcp_listen_any(int port, int backlog, std::string& stage) {
447 const int fd = ::socket(AF_INET, SOCK_STREAM, 0);
448 if (fd < 0) {
449 stage = "socket";
450 return kInvalidSocket;
451 }
452 int yes = 1;
453 ::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
454 struct sockaddr_in addr;
455 std::memset(&addr, 0, sizeof(addr));
456 addr.sin_family = AF_INET;
457 addr.sin_addr.s_addr = htonl(INADDR_ANY);
458 addr.sin_port = htons(static_cast<uint16_t>(port));
459 if (::bind(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) != 0) {
460 ::close(fd);
461 stage = "bind";
462 return kInvalidSocket;
463 }
464 if (::listen(fd, backlog) != 0) {
465 ::close(fd);
466 stage = "listen";
467 return kInvalidSocket;
468 }
469 return static_cast<socket_t>(fd);
470}
471
472inline socket_t tcp_accept(socket_t listener) {
473 const int c = ::accept(static_cast<int>(listener), nullptr, nullptr);
474 return c < 0 ? kInvalidSocket : static_cast<socket_t>(c);
475}
476
477/**
478 * A loopback port the kernel reports free (bind port 0, read it back), or -1
479 * with the failing step in `stage` ("socket", "bind" or "getsockname").
480 */
481inline int free_loopback_port(std::string& stage) {
482 const int fd = ::socket(AF_INET, SOCK_STREAM, 0);
483 if (fd < 0) {
484 stage = "socket";
485 return -1;
486 }
487 struct sockaddr_in addr;
488 std::memset(&addr, 0, sizeof(addr));
489 addr.sin_family = AF_INET;
490 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
491 addr.sin_port = 0;
492 if (::bind(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) != 0) {
493 ::close(fd);
494 stage = "bind";
495 return -1;
496 }
497 socklen_t len = sizeof(addr);
498 if (::getsockname(fd, reinterpret_cast<struct sockaddr*>(&addr), &len) != 0) {
499 ::close(fd);
500 stage = "getsockname";
501 return -1;
502 }
503 const int port = ntohs(addr.sin_port);
504 ::close(fd);
505 return port;
506}
507
508/** send() without SIGPIPE; bytes sent or -1. */
509inline long send_some(socket_t s, const char* p, std::size_t n) {
510#ifdef MSG_NOSIGNAL
511 const int flags = MSG_NOSIGNAL;
512#else
513 const int flags = 0;
514#endif
515 return static_cast<long>(::send(static_cast<int>(s), p, n, flags));
516}
517
518inline long recv_some(socket_t s, char* p, std::size_t n) {
519 return static_cast<long>(::recv(static_cast<int>(s), p, n, 0));
520}
521
522inline void close_socket(socket_t s) {
523 if (s != kInvalidSocket) ::close(static_cast<int>(s));
524}
525
526inline int last_socket_error() { return errno; }
527inline bool err_interrupted(int e) { return e == EINTR; }
528inline bool err_timed_out(int e) { return e == EAGAIN || e == EWOULDBLOCK; }
529inline std::string socket_error_text(int e) { return std::strerror(e); }
530
531#endif // _WIN32
532
533} // namespace platform
534} // namespace line
535
536#endif // LINE_UTIL_PLATFORM_H
double available_memory_bytes()
Available physical memory in bytes; negative when the host cannot say.
Definition platform.h:277
bool make_dir_or_exists(const std::string &path)
mkdir 0700; an existing entry is success.
Definition platform.h:216
int dup2_fd(int from, int to)
POSIX dup2 returns the new descriptor; the CRT's _dup2 returns 0.
Definition platform.h:238
bool err_interrupted(int e)
Definition platform.h:527
long process_id()
Definition platform.h:265
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...
Definition platform.h:412
bool is_writable(const std::string &p)
Definition platform.h:159
bool is_regular_file(const std::string &p)
Definition platform.h:143
bool is_directory(const std::string &p)
Definition platform.h:148
bool rename_replace(const std::string &from, const std::string &to)
Definition platform.h:241
int last_socket_error()
Definition platform.h:526
std::intptr_t socket_t
A TCP socket: a POSIX descriptor or a Winsock SOCKET.
Definition platform.h:61
std::string temp_root()
TMPDIR, else /tmp.
Definition platform.h:132
static const socket_t kInvalidSocket
Definition platform.h:62
bool is_executable(const std::string &p)
Exists and the caller may execute it (a directory with +x included, as access() says).
Definition platform.h:154
std::string make_temp_dir(const std::string &tmpl)
mkdtemp on a template ending in XXXXXX; empty on failure.
Definition platform.h:221
long send_some(socket_t s, const char *p, std::size_t n)
send() without SIGPIPE; bytes sent or -1.
Definition platform.h:509
char path_list_separator()
Definition platform.h:127
std::string host_machine()
uname -m, or empty.
Definition platform.h:210
bool stat_file(const std::string &p, FileStat &out)
Definition platform.h:163
socket_t tcp_accept(socket_t listener)
Definition platform.h:472
bool docker_user_spec(std::string &out)
"uid:gid" for docker run --user; false where the notion does not apply.
Definition platform.h:302
socket_t tcp_listen_any(int port, int backlog, std::string &stage)
An IPv4 listener on every interface with SO_REUSEADDR.
Definition platform.h:446
std::string self_exe_path()
This executable's path, or empty when it cannot be read.
Definition platform.h:191
int dup_fd(int fd)
Definition platform.h:237
void set_io_timeout(socket_t s, int millis)
Set the receive and send timeouts; not positive leaves them as they are.
Definition platform.h:397
std::string current_dir()
Definition platform.h:198
std::string host_sysname()
uname -s, or empty.
Definition platform.h:204
const char * null_device()
Definition platform.h:128
bool spawn_detached(const std::vector< std::string > &argv)
Start argv detached (own session, std streams on /dev/null, double fork so no zombie).
Definition platform.h:309
int make_temp_file(std::string &tmpl)
mkstemp: replaces the XXXXXX in tmpl and returns an open descriptor, or -1.
Definition platform.h:229
long long free_disk_bytes(const std::string &path)
Bytes available to this user on the filesystem holding path; -1 if unknown.
Definition platform.h:268
void sleep_millis(long millis)
Definition platform.h:294
int close_fd(int fd)
Definition platform.h:239
void remove_tree(const std::string &dir)
Remove a directory and everything under it, not following symlinks.
Definition platform.h:246
bool err_timed_out(int e)
A Winsock receive timeout reports WSAETIMEDOUT where POSIX reports EAGAIN.
Definition platform.h:528
std::string find_on_path(const std::string &name)
The first dir/name on PATH that is a regular executable file, or empty.
Definition platform.h:174
long recv_some(socket_t s, char *p, std::size_t n)
Definition platform.h:518
const char * exe_suffix()
Definition platform.h:129
void close_socket(socket_t s)
Definition platform.h:522
std::string socket_error_text(int e)
Definition platform.h:529
bool remove_file(const std::string &p)
Definition platform.h:240
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,...
Definition platform.h:340
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 s...
Definition platform.h:481
std::string home_dir()
HOME, or empty.
Definition platform.h:138
long long monotonic_millis()
Milliseconds on the monotonic clock, for deadlines that survive a clock step.
Definition platform.h:288
ConnectFailure
Why tcp_connect failed, so the caller keeps its own wording.
Definition platform.h:73
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
What stat_file reports.
Definition platform.h:65
long long size
bytes
Definition platform.h:66
long long mtime
seconds since the epoch
Definition platform.h:67