aboutsummaryrefslogtreecommitdiff
path: root/src/net/common.h
blob: 6bb161cf6a895422f462d5d66a2280d92189f3bb (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef __common_net_h
#define __common_net_h

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>

#include "../net.h"
#include "../lua.h"
#include "../io.h"
#include "../table.h"
#include "../types/str.h"
#include "../types/parray.h"
#include "../types/map.h"

#define max_con 200
//2^42
#define MAX_HEADER_SIZE (1<<20)
#define BUFFER_SIZE 20000
#define HTTP_BUFFER_SIZE 4098
#define max_content_length 200000

enum file_status {
  _ignore, BARRIER_READ, FILE_HEADER, FILE_BODY, NORMAL
};

struct file_parse {
  enum file_status status;
  str *current, *old, *boundary, *boundary_id;
  int dash_count, table_idx;
};

typedef struct {
  int fd, ser;
  int port;
  lua_State* L;
  struct sockaddr_in cli;
  parray_t* paths;
} thread_arg_struct;

struct lchar {
  char* c;
  int len;
  char req[20];
};

struct net_server_state {
  int event_fd;
};

struct sarray_t {
  struct lchar** cs;
  int len;
};

extern map_t* mime_type;

int start_serv(lua_State* L, int port, parray_t* paths, struct net_server_state*);

enum {
  NETEV_NULL = 0,
  NETEV_DEFAULT = 1,
  NETEV_CLOSE_EVENT = 2,
};

#endif