You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
865 B
40 lines
865 B
#ifndef __SERVER_H__
|
|
#define __SERVER_H__
|
|
|
|
#include <stdio.h> /* for printf() and fprintf() */
|
|
#include <poll.h> /* for select system call and related */
|
|
|
|
#include "socket.h"
|
|
#include "logger.h"
|
|
#include "cclass.h"
|
|
|
|
#define POLL_FD_NSIZE 1024
|
|
#define POLL_FD_SIZE (sizeof(struct pollfd) * POLL_FD_NSIZE)
|
|
#define POLL_FD_MOVE(idx) (sizeof(struct pollfd) * (POLL_FD_NSIZE-(idx)+1))
|
|
|
|
|
|
typedef void (*server_read_hook)(const char *);
|
|
|
|
CLASS(SERVER) {
|
|
LOGGER logger;
|
|
SOCK sock;
|
|
nfds_t nfds;
|
|
struct pollfd fds[POLL_FD_NSIZE];
|
|
|
|
struct {
|
|
SOCK sock;
|
|
char * wbuf;
|
|
char * rbuf;
|
|
unsigned int rpos;
|
|
unsigned int wpos;
|
|
} conns[POLL_FD_NSIZE];
|
|
|
|
server_read_hook read_hook;
|
|
};
|
|
|
|
void server_run(SERVER this);
|
|
void server_close_conn(SERVER this, unsigned int handle);
|
|
|
|
#endif // __SERVER_H__
|
|
|
|
// vim: set ts=4 sw=4:
|