menios icon indicating copy to clipboard operation
menios copied to clipboard

Implement Unix domain sockets (AF_UNIX) for IPC

Open pbalduino opened this issue 3 months ago • 0 comments

Summary

Implement Unix domain sockets (AF_UNIX) for inter-process communication between GUI clients and the compositor. This provides the transport layer for the window protocol.

Background

Unix domain sockets provide reliable, bidirectional IPC. They're used by Wayland, X11, D-Bus, and most Linux IPC mechanisms.

Goals

  • Implement AF_UNIX socket family
  • Support SOCK_STREAM (connection-oriented)
  • Implement socket(), bind(), listen(), accept(), connect()
  • Support credential passing (SCM_RIGHTS) for fd passing
  • Filesystem-based socket naming

Implementation

Socket API

```c // Create socket int socket(int domain, int type, int protocol); // domain=AF_UNIX, type=SOCK_STREAM

// Bind to path int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

struct sockaddr_un { sa_family_t sun_family; // AF_UNIX char sun_path[108]; // Path (e.g., "/tmp/compositor") };

// Listen/accept int listen(int sockfd, int backlog); int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

// Connect int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

// Send/receive with file descriptor passing ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags); ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags); ```

Usage Example (Compositor Server)

```c int sock = socket(AF_UNIX, SOCK_STREAM, 0);

struct sockaddr_un addr = { .sun_family = AF_UNIX, .sun_path = "/tmp/meni-compositor" };

bind(sock, (struct sockaddr*)&addr, sizeof(addr)); listen(sock, 5);

while (1) { int client = accept(sock, NULL, NULL); // Handle client connection } ```

Usage Example (GUI Client)

```c int sock = socket(AF_UNIX, SOCK_STREAM, 0);

struct sockaddr_un addr = { .sun_family = AF_UNIX, .sun_path = "/tmp/meni-compositor" };

connect(sock, (struct sockaddr*)&addr, sizeof(addr));

// Send window protocol messages write(sock, &msg, sizeof(msg)); ```

Timeline

Total: 1-2 weeks

Definition of Done

  • [ ] AF_UNIX socket family implemented
  • [ ] socket/bind/listen/accept/connect work
  • [ ] send/recv work
  • [ ] Credential passing (SCM_RIGHTS) works
  • [ ] Multiple clients can connect
  • [ ] Test suite passes

Dependencies

  • #193: libc (socket API)

Enables

  • Compositor protocol (critical for client-server communication)

See docs/road/road_to_gui.md for complete roadmap.

pbalduino avatar Oct 30 '25 22:10 pbalduino