A low-key HTTP micro-framework for people who hate web bloat
git clone git://soophie.de/tpee
165
#include <netdb.h>166
#include <poll.h>167
#include <signal.h>168
#include <fcntl.h>169
#include <openssl/ssl.h>170
#include <sys/socket.h>
333
}335
ssize_t http_read(http_conn_t *conn, char *buffer, size_t len) {335
struct pollfd fds[1];336
fds[0].fd = conn->sockfd;337
fds[0].events = POLLIN | POLLPRI;338
if (poll(fds, 1, 100) && fds[0].revents & POLLIN) {339
if (conn->ssl != NULL) {340
return SSL_read(conn->ssl, buffer, len);341
}342
return read(conn->sockfd, buffer, len);336
if (conn->ssl != NULL) {337
return SSL_read(conn->ssl, buffer, len);338
}344
return 0;339
return read(conn->sockfd, buffer, len);340
}342
ssize_t http_write(http_conn_t *conn, char *buffer, size_t len) {
605
pthread_exit(0);606
}607
}608
int flags = fcntl(conn->sockfd, F_GETFL, 0);609
if (flags == -1) {610
close(conn->sockfd);611
free(conn);612
pthread_exit(0);613
}614
flags |= O_NONBLOCK;615
if (fcntl(conn->sockfd, F_SETFL, flags) == -1) {616
close(conn->sockfd);617
free(conn);618
pthread_exit(0);619
}620
http_request_t request = http_read_request(conn);621
if (request.method != NULL && request.url != NULL) {622
if (conn->http->on_request_fn != NULL) {