-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsocket.h
38 lines (30 loc) · 1.07 KB
/
socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include "vector.h"
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#define LINEBUFFER_SIZE 1024
enum socket_command { CLIENT_GETSTATUS, CLIENT_SET_VOLUME, CLIENT_SETLATENCY, CLIENT_SETNAME, SERVER_GETRPCVERSION, SERVER_GETSTATUS };
// GROUP_GETSTATUS, GROUP_GETMUTE, GROUP_SETSTREAM, GROUP_SETCLIENTS, SERVER_DELETECLIENT
// enum socket_notifications {}
// CLIENT_ONCONNECT, CLIENT_ONDISCONNECT, CLIENT_ONVOLUMECHANGED,
// CLIENT_ONLATENCYCHANGED, CLIENT_ONNAMECHANGED, GROUP_ONMUTE,
// GROUP_ONSTREAMCHANGED, STREAM_ONUPDATE, SERVER_ONUPDATE
typedef struct {
int fd;
char line[LINEBUFFER_SIZE];
int line_offset;
} socketclient;
typedef struct {
int fd;
uint16_t port;
VECTOR(socketclient) clients;
} socket_ctx;
void socket_init(socket_ctx *ctx);
int socket_handle_in(socket_ctx *ctx);
bool socket_get_client(socket_ctx *ctx, socketclient **sc_dest, int fd);
int socket_handle_client(socket_ctx *ctx, socketclient *sc);
void socket_client_remove(socket_ctx *ctx, socketclient *sc);