tskrtt

Simple libev based gopher server
git clone https://git.inz.fi/tskrtt/
Log | Files | Refs | README

client.h (1086B)


      1 #ifndef CLIENT_H
      2 #define CLIENT_H
      3 
      4 #include <sys/socket.h>
      5 
      6 #include <netinet/in.h>
      7 #include <stdbool.h>
      8 
      9 #include <ev.h>
     10 
     11 #include "task.h"
     12 
     13 #ifdef USE_TLS
     14 enum tls_state {
     15 	UNKNOWN,
     16 	PLAIN,
     17 	HANDSHAKE,
     18 	READY
     19 };
     20 #endif
     21 
     22 struct client {
     23 	bool broken_client;
     24 	ev_io watcher;
     25 	ev_timer timeout;
     26 	struct sockaddr_storage addr;
     27 	socklen_t addrlen;
     28 	int fd;
     29 	char buffer[2048];
     30 	size_t buffer_used;
     31 	enum task task;
     32 	union {
     33 		struct dir_task dt;
     34 		struct txt_task tt;
     35 		struct gph_task gpht;
     36 		struct binary_task bt;
     37 		struct cgi_task ct;
     38 		struct dcgi_task dct;
     39 	} task_data;
     40 #ifdef USE_TLS
     41 	struct tls *tlsctx;
     42 	enum tls_state tlsstate;
     43 #endif
     44 };
     45 
     46 struct client *client_new(EV_P_ int fd, struct sockaddr *addr, socklen_t addrlen
     47 #ifdef USE_TLS
     48 		, struct tls *tlsctx
     49 #endif
     50 		);
     51 bool client_printf(struct client *c, const char *fmt, ...);
     52 void client_close(EV_P_ struct client *c);
     53 void client_error(EV_P_ struct client *c, const char *fmt, ...);
     54 bool client_eos(struct client *c);
     55 int client_write(struct client *c, void *buffer, size_t n);
     56 bool client_flush(struct client *c);
     57 
     58 #endif