A low-key HTTP micro-framework for people who hate web bloat
git clone git://soophie.de/tpee
2
#include <stdlib.h>3
#include <stdbool.h>4
#include <string.h>5
#include <time.h>6
#include <unistd.h>7
#include <pthread.h>8
#include <netdb.h>
299
int len = 0;300
int ln = 0;301
int start = 0;301
char buffer[10240];302
char buffer[MAX_REQUEST_HEAD_SIZE];303
http_request_t request = { conn, NULL, NULL, NULL, NULL, 0, NULL, 0 };304
while (true) {305
char c;305
http_read(conn, &c, 1);306
int read = http_read(conn, &c, 1);307
if (read == 0) {308
break;309
}310
// break if too long311
if (len == MAX_REQUEST_HEAD_SIZE) {312
perror("request is too long");
473
fds[0].fd = sockfd;474
fds[0].events = POLLIN | POLLPRI;475
while (!http_quit) {472
usleep(100000);476
struct timespec sleep_req, sleep_rem;477
sleep_req.tv_sec = 0;478
sleep_req.tv_nsec = 100000000;479
nanosleep(&sleep_req, &sleep_rem);480
if (poll(fds, 1, 100)) {481
conn_t *conn = malloc(sizeof(conn_t));482
conn->addr_len = sizeof(conn->addr);
487
}488
else {489
pthread_t thread;483
pthread_create(&thread, 0, http_handle_client, (void *) conn);484
pthread_detach(thread);490
pthread_attr_t thread_attr;491
pthread_attr_init(&thread_attr);492
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);493
pthread_create(&thread, &thread_attr, http_handle_client, (void *) conn);494
pthread_attr_destroy(&thread_attr);495
}496
}497
}