feat: implement new IPC layer

This commit is contained in:
2026-04-01 13:11:03 +02:00
parent 6276f8b162
commit 346977a0f9
34 changed files with 3210 additions and 897 deletions
+19 -5
View File
@@ -390,11 +390,14 @@ bool desktop_poll_external_windows(DesktopState* ds) {
for (int i = 0; i < ds->window_count; i++) {
if (ds->windows[i].external && ds->windows[i].ext_win_id == extId) {
found = true;
bool remapRequested = false;
uint64_t currentVa = (uint64_t)(uintptr_t)ds->windows[i].content;
if (ds->windows[i].content_w != extWins[e].width ||
ds->windows[i].content_h != extWins[e].height) {
ds->windows[i].content_w = extWins[e].width;
ds->windows[i].content_h = extWins[e].height;
ds->windows[i].dirty = true;
remapRequested = true;
if (ds->windows[i].state != WIN_MINIMIZED && ds->windows[i].state != WIN_CLOSED) {
changed = true;
}
@@ -411,12 +414,20 @@ bool desktop_poll_external_windows(DesktopState* ds) {
changed = true;
}
ds->windows[i].ext_cursor = extWins[e].cursor;
// Always verify mapping is current. If a window slot was
// recycled (app exited, new app got same slot), desktopVa
// was zeroed and Map() returns a new VA. Detect this and
// update the content pointer to avoid using a stale VA.
if (remapRequested && currentVa != 0) {
montauk::win_unmap(extId);
ds->windows[i].content = nullptr;
currentVa = 0;
}
uint64_t va = montauk::win_map(extId);
if (va != 0 && va != (uint64_t)(uintptr_t)ds->windows[i].content) {
if (!remapRequested && va != 0 && va != currentVa) {
montauk::win_unmap(extId);
va = montauk::win_map(extId);
}
if (va != 0 && va != currentVa) {
ds->windows[i].content = (uint32_t*)va;
ds->windows[i].content_w = extWins[e].width;
ds->windows[i].content_h = extWins[e].height;
@@ -508,6 +519,9 @@ bool desktop_poll_external_windows(DesktopState* ds) {
if (!stillExists) {
// Window gone — remove without freeing content (shared memory)
if (ds->windows[i].content != nullptr) {
montauk::win_unmap(extId);
}
ds->windows[i].content = nullptr; // prevent free
gui::desktop_close_window(ds, i);
changed = true;
+6 -2
View File
@@ -397,7 +397,9 @@ extern "C" void _start() {
}
}
}
montauk::yield();
uint64_t now = montauk::get_milliseconds();
if (now >= startMs + 10000) break;
montauk::wait_handle(fd, Montauk::IPC_SIGNAL_READABLE, startMs + 10000 - now);
}
if (!gotOffer) {
@@ -447,7 +449,9 @@ extern "C" void _start() {
}
}
}
montauk::yield();
uint64_t now = montauk::get_milliseconds();
if (now >= startMs + 10000) break;
montauk::wait_handle(fd, Montauk::IPC_SIGNAL_READABLE, startMs + 10000 - now);
}
montauk::closesocket(fd);
+8 -2
View File
@@ -198,8 +198,14 @@ static int plain_http_exchange(int fd, const char* request, int reqLen,
if (r > 0) { respLen += r; deadline = montauk::get_milliseconds() + 15000; }
else if (r < 0) break;
else {
if (montauk::get_milliseconds() >= deadline) break;
montauk::sleep_ms(1);
uint64_t now = montauk::get_milliseconds();
if (now >= deadline) break;
uint32_t signals = montauk::wait_handle(
fd,
Montauk::IPC_SIGNAL_READABLE | Montauk::IPC_SIGNAL_PEER_CLOSED,
deadline - now
);
if (signals == 0 || signals == (uint32_t)-1) break;
}
}
return respLen;
+11 -3
View File
@@ -386,9 +386,17 @@ static void handle_client(int clientFd) {
} else if (r == 0) {
break; // Connection closed
} else {
idleCount++;
if (idleCount > 500) break; // Timeout
montauk::yield();
uint32_t signals = montauk::wait_handle(
clientFd,
Montauk::IPC_SIGNAL_READABLE | Montauk::IPC_SIGNAL_PEER_CLOSED,
20
);
if (signals == 0) {
idleCount++;
if (idleCount > 500) break;
} else if (signals & Montauk::IPC_SIGNAL_PEER_CLOSED) {
break;
}
}
}
reqBuf[reqLen] = '\0';
+3 -1
View File
@@ -1028,7 +1028,9 @@ extern "C" void _start() {
}
} else {
if (!dirty) {
montauk::yield();
montauk::wait_handle(irc.fd,
Montauk::IPC_SIGNAL_READABLE | Montauk::IPC_SIGNAL_PEER_CLOSED,
10);
continue;
}
}
+1 -2
View File
@@ -187,8 +187,7 @@ extern "C" void _start() {
montauk::putchar(ev.ascii);
}
} else {
// No key and no data -- yield to avoid busy-spinning
montauk::yield();
montauk::wait_handle(fd, Montauk::IPC_SIGNAL_READABLE | Montauk::IPC_SIGNAL_PEER_CLOSED, 10);
}
}