Skip to content
Snippets Groups Projects
Commit 34db2b71 authored by alin_andrei.enasoiu's avatar alin_andrei.enasoiu
Browse files

final failed attempt

parent 527e468d
No related branches found
No related tags found
No related merge requests found
Pipeline #24856 passed
......@@ -47,23 +47,22 @@ static int aws_on_path_cb(http_parser *p, const char *buf, size_t len)
static void prepare_connection_send_reply_header(struct connection *conn)
{
memset(conn->send_buffer, 0, sizeof(conn->send_buffer));
sprintf(conn->send_buffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: %ld\r\n\r\n", conn->file_size);
sprintf(conn->send_buffer,
"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n");
conn->send_len = strlen(conn->send_buffer);
}
static void prepare_connection_send_404(struct connection *conn)
{
memset(conn->send_buffer, 0, sizeof(conn->send_buffer));
sprintf(conn->send_buffer, "HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\nContent-Length: %ld\r\n\r\n", conn->file_size);
sprintf(conn->send_buffer,
"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n");
conn->send_len = strlen(conn->send_buffer);
}
static enum resource_type connection_get_resource_type(struct connection *conn)
{
return RESOURCE_TYPE_NONE;
}
......@@ -79,16 +78,12 @@ struct connection *connection_create(int sockfd)
void connection_start_async_io(struct connection *conn)
{
}
void connection_remove(struct connection *conn)
{
w_epoll_remove_fd(epollfd, conn->sockfd);
close(conn->sockfd);
free(conn);
}
......@@ -107,12 +102,10 @@ void handle_new_connection(void)
http_parser_init(&(conn->request_parser), HTTP_REQUEST);
conn->request_parser.data = conn;
}
void receive_data(struct connection *conn)
{
memset(conn->recv_buffer, 0, sizeof(conn->recv_buffer));
int bytes = recv(conn->sockfd, conn->recv_buffer, sizeof(conn->recv_buffer), 0);
......@@ -121,13 +114,11 @@ void receive_data(struct connection *conn)
int connection_open_file(struct connection *conn)
{
return 0;
}
void connection_complete_async_io(struct connection *conn)
{
}
int parse_header(struct connection *conn)
......@@ -152,25 +143,21 @@ int parse_header(struct connection *conn)
enum connection_state connection_send_static(struct connection *conn)
{
return STATE_NO_STATE;
}
int connection_send_data(struct connection *conn)
{
return 0;
}
int connection_send_dynamic(struct connection *conn)
{
return 0;
}
void handle_input(struct connection *conn)
{
switch (conn->state) {
case STATE_INITIAL:
receive_data(conn);
......@@ -191,20 +178,18 @@ void handle_input(struct connection *conn)
void handle_output(struct connection *conn)
{
switch (conn->state) {
case STATE_SENDING_HEADER:
send(conn->sockfd, conn->send_buffer, conn->send_len, 0);
break;
default:
break;
}
}
void handle_client(uint32_t event, struct connection *conn)
{
switch (event) {
case EPOLLIN:
handle_input(conn);
......@@ -215,12 +200,12 @@ void handle_client(uint32_t event, struct connection *conn)
break;
default:
break;
}
}
int main(void)
{
epollfd = epoll_create(1);
DIE(epollfd < 0, "epoll_create");
......@@ -251,9 +236,7 @@ int main(void)
int rc = epoll_wait(epollfd, &rev, 1, -1);
if (rc < 0)
DIE(rc < 0, "epoll_wait");
DIE(rc < 0, "epoll_wait");
if (rev.data.fd == listenfd)
handle_new_connection();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment