aboutsummaryrefslogtreecommitdiff
path: root/Server.h
blob: 0a555439b78549c64bf52a295924591d0bdd77bd (plain)
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
45
46
47
48
#ifndef Server_h
#define Server_h

#include <sys/socket.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <pthread.h>
 
struct AcceptedSocket{
    int socketFD;
    struct sockaddr_in address;
    int error;
    bool succ;
    pthread_t thread_id;
    bool shutdown;

    struct AcceptedSocket *next;
};

struct Server{
    int domain;
    int service;
    int protocol;
    u_long interface;
    int port;
    int backlog;
    bool running;

    struct sockaddr_in address;

    int socket;
    char *html_folder;

    struct AcceptedSocket *accepted_socket;

    pthread_t (*launch)(struct Server *server);
    void (*on_message)(struct Server *server, char message[], ssize_t amountRecv, int socketFD);
    void (*on_disconnect)(struct Server *server, int socketFD);
};

/*
 * AF_INET, SOCK_STREAM, 0, INADDR_ANY, port, 10, launch_socket
 * or
 * AF_INET, SOCK_STREAM, 0, INADDR_ANY, port, 10, launch
 */
struct Server server_constructor(int domain, int service, int protocol, u_long interface, int port, int backlog, pthread_t (*launch)(struct Server *server));

#endif /* Server_h */