Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Assignment Async Web Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alin-Andrei ENASOIU
Assignment Async Web Server
Commits
34db2b71
Commit
34db2b71
authored
1 year ago
by
alin_andrei.enasoiu
Browse files
Options
Downloads
Patches
Plain Diff
final failed attempt
parent
527e468d
No related branches found
No related tags found
No related merge requests found
Pipeline
#24856
passed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/aws.c
+7
-24
7 additions, 24 deletions
src/aws.c
with
7 additions
and
24 deletions
src/aws.c
+
7
−
24
View file @
34db2b71
...
...
@@ -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\n
Content-Type: text/html
\r\n
Content-Length: %ld
\r\n\r\n
"
,
conn
->
file_size
);
sprintf
(
conn
->
send_buffer
,
"HTTP/1.1 200 OK
\r\n
Content-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\n
Content-Type: text/html
\r\n
Content-Length: %ld
\r\n\r\n
"
,
conn
->
file_size
);
sprintf
(
conn
->
send_buffer
,
"HTTP/1.1 200 OK
\r\n
Content-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
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment