jitterbug/server.h

47 lines
989 B
C
Raw Normal View History

#ifndef _JITTERBUG__SERVER_H
#define _JITTERBUG__SERVER_H
#include <poll.h>
#include <stdint.h>
// TODO: dynamically size the arrays
#define JB_MAX_CLIENTS 256
#define JB_MAX_NAMES 512
#define JB_BACKLOG 12
enum {
JB_CLIENT_STATE_NONE,
JB_CLIENT_STATE_WAIT_AUTH,
JB_CLIENT_STATE_WAIT_BEGIN,
JB_CLIENT_STATE_READY
};
struct jb_client {
int fd;
uint8_t state;
int16_t unique_name_index;
int16_t owned_name_index;
};
struct jb_name {
char *name;
int16_t client_index;
};
struct jb_server {
int sock_fd;
int fd_num;
struct jb_client clients[JB_MAX_CLIENTS];
struct jb_name names[JB_MAX_NAMES];
struct pollfd fds[JB_MAX_CLIENTS + 1];
};
int jb_server_client_add(struct jb_server *s, int fd);
void jb_server_client_remove(struct jb_server *s, int i);
void jb_server_free(struct jb_server *s);
struct jb_server *jb_server_create(const char *socket_path);
int jb_server_turn(struct jb_server *s);
#endif // _JITTERBUG__SERVER_H