2020-09-23 12:40:28 -04:00
|
|
|
#ifndef GMNISRV_SERVER
|
|
|
|
#define GMNISRV_SERVER
|
|
|
|
#include <poll.h>
|
2020-09-23 14:19:28 -04:00
|
|
|
#include <stdbool.h>
|
2020-09-23 12:40:28 -04:00
|
|
|
|
|
|
|
#define GEMINI_MAX_URL 1024
|
|
|
|
|
|
|
|
struct gmnisrv_client {
|
2020-09-23 14:19:28 -04:00
|
|
|
struct sockaddr addr;
|
|
|
|
socklen_t addrlen;
|
|
|
|
|
2020-09-23 12:40:28 -04:00
|
|
|
char buf[GEMINI_MAX_URL + 2];
|
|
|
|
size_t bufln;
|
2020-09-23 14:19:28 -04:00
|
|
|
|
2020-09-23 12:40:28 -04:00
|
|
|
int sockfd;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gmisrv_config;
|
|
|
|
|
|
|
|
struct gmnisrv_server {
|
|
|
|
struct gmnisrv_config *conf;
|
|
|
|
struct pollfd *fds;
|
|
|
|
nfds_t nfds, fdsz;
|
|
|
|
|
2020-09-23 14:19:28 -04:00
|
|
|
// nlisten is initialized once and does not change. The fds list starts
|
|
|
|
// with this many listening sockets, then has sockets for each active
|
|
|
|
// client, up to nfds.
|
2020-09-23 12:40:28 -04:00
|
|
|
size_t nlisten;
|
|
|
|
|
|
|
|
struct gmnisrv_client *clients;
|
|
|
|
size_t nclients, clientsz;
|
2020-09-23 14:19:28 -04:00
|
|
|
|
|
|
|
bool run;
|
2020-09-23 12:40:28 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
int server_init(struct gmnisrv_server *server, struct gmnisrv_config *conf);
|
|
|
|
void server_run(struct gmnisrv_server *server);
|
|
|
|
void server_finish(struct gmnisrv_server *server);
|
|
|
|
|
|
|
|
#endif
|