seatd/include/connection.h
Kenny Levinsen 8b4d139873 libseat: Improve logging with seatd conn helpers
Add helpers around connection access to have all logging centralized and
reduce code duplication. Improve existing helpers to further reduce code
duplication.

The seatd backend should have much better logging after this.
2020-08-29 20:56:42 +02:00

36 lines
1,014 B
C

#ifndef _SEATD_CONNECTION_H
#define _SEATD_CONNECTION_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define CONNECTION_BUFFER_SIZE 256
#define MAX_FDS (CONNECTION_BUFFER_SIZE / sizeof(int))
struct connection_buffer {
uint32_t head, tail;
char data[CONNECTION_BUFFER_SIZE];
};
struct connection {
struct connection_buffer in, out;
struct connection_buffer fds_in, fds_out;
int fd;
bool want_flush;
};
int connection_read(struct connection *connection);
int connection_flush(struct connection *connection);
int connection_put(struct connection *connection, const void *data, size_t count);
int connection_put_fd(struct connection *connection, int fd);
size_t connection_pending(struct connection *connection);
int connection_get(struct connection *connection, void *dst, size_t count);
int connection_get_fd(struct connection *connection, int *fd);
void connection_restore(struct connection *connection, size_t count);
void connection_close_fds(struct connection *connection);
#endif