summaryrefslogtreecommitdiffstats
path: root/include/server.h
blob: 5624b52dabbc92506f4316d58a097576cbbb4bd6 (plain) (blame)
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
39
40
41
42
43
44
#ifndef GMNISRV_SERVER
#define GMNISRV_SERVER
#include <openssl/ssl.h>
#include <poll.h>
#include <stdbool.h>

#define GEMINI_MAX_URL 1024

struct gmnisrv_client {
	struct sockaddr addr;
	socklen_t addrlen;
	int sockfd;

	SSL *ssl;
	BIO *bio;

	char buf[GEMINI_MAX_URL + 3];

	struct gmnisrv_host *host;
};

struct gmisrv_config;

struct gmnisrv_server {
	struct gmnisrv_config *conf;
	struct pollfd *fds;
	nfds_t nfds, fdsz;

	// 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.
	size_t nlisten;

	struct gmnisrv_client *clients;
	size_t nclients, clientsz;

	bool run;
};

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