eis: Add API to add client getting an fd

Creates the socket and adds it; is intended to be used to create client
connections that are passed via a secure channel, e.g. via portals.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
This commit is contained in:
Jonas Ådahl 2022-04-21 23:02:04 +02:00 committed by Peter Hutterer
parent a330b31713
commit e115c6549b
2 changed files with 31 additions and 1 deletions

View file

@ -86,3 +86,24 @@ eis_backend_fd_add_fd(struct eis *eis, int fd)
return 0;
}
_public_ int
eis_backend_fd_add_client(struct eis *eis)
{
assert(eis);
assert(eis->backend);
int fds[2];
int rc = socketpair(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK|SOCK_CLOEXEC, 0, fds);
if (rc == -1)
return -errno;
struct eis_client *client = eis_client_new(eis, fds[0]);
if (client == NULL)
return -ENOMEM;
eis_client_unref(client);
return fds[1];
}

View file

@ -403,11 +403,20 @@ int
eis_setup_backend_fd(struct eis *ctx);
/**
* Add a new client to a context set up with eis_setup_backend_fd()
* Add a new client given a file descriptor to a context set up with
* eis_setup_backend_fd()
*/
int
eis_backend_fd_add_fd(struct eis *ctx, int fd);
/**
* Add a new client to a context set up with eis_setup_backend_fd(). Returns
* a file descriptor to be passed to ei_setup_backend_fd(), or a negative
* errno on failure.
*/
int
eis_backend_fd_add_client(struct eis *ctx);
/**
* libeis keeps a single file descriptor for all events. This fd should be
* monitored for events by the caller's mainloop, e.g. using select(). When