summaryrefslogtreecommitdiff
path: root/jet.cpp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-17 16:23:43 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-17 16:23:43 -0300
commitd608bef678fa97b3af910fa62598c55f33650825 (patch)
tree90f1b4029be89a3ed3c55593b9787371c8037a35 /jet.cpp
parentc1d93b0bc5a2abcf5e7cadd17ef9db7f57a524fc (diff)
downloadjet-d608bef678fa97b3af910fa62598c55f33650825.tar.gz
jet-d608bef678fa97b3af910fa62598c55f33650825.zip
Restructure source files
Diffstat (limited to 'jet.cpp')
-rw-r--r--jet.cpp72
1 files changed, 0 insertions, 72 deletions
diff --git a/jet.cpp b/jet.cpp
deleted file mode 100644
index 2006a77..0000000
--- a/jet.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/ip.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <sys/epoll.h>
-
-#include "ipc.cpp"
-#include "page.cpp"
-#include "buffer.cpp"
-#include "point.cpp"
-#include "client.cpp"
-
-#define PORT 6969
-#define MAX_EVENTS 10
-
-int create_listener() {
- int s = socket(AF_INET, SOCK_STREAM, 0);
- sockaddr_in addr = { AF_INET, htons(PORT), htonl(INADDR_LOOPBACK)};
- int opt = 1;
- setsockopt(s, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt));
- bind(s, (sockaddr *) &addr, sizeof(sockaddr_in));
- listen(s, MAX_EVENTS);
- return s;
-}
-
-int main() {
- Buffer scratch("scratch");
- scratch.read_file("LICENSE");
-
- int listener = create_listener();
-
- int epollfd = epoll_create1(0);
-
- epoll_event ev;
- ev.events = EPOLLIN;
- ev.data.fd = listener;
- epoll_ctl(epollfd, EPOLL_CTL_ADD, listener, &ev);
-
- epoll_event events[MAX_EVENTS];
- Client *clients[1024] = {};
-
- while (true) {
- int nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
-
- for (int i = 0; i < nfds; i++) {
- if (events[i].data.fd == listener) {
- int clientfd = accept(listener, 0, 0);
- ev.events = EPOLLIN | EPOLLET;
- ev.data.fd = clientfd;
- if (clients[clientfd]) {
- delete clients[clientfd];
- }
- Client *c = new Client(scratch);
- c->sockfd = clientfd;
- clients[clientfd] = c;
- epoll_ctl(epollfd, EPOLL_CTL_ADD, clientfd, &ev);
- } else {
- clients[events[i].data.fd]->parse_message();
- }
- }
- }
-
- close(listener);
-}