Skip to content

Commit 78d0718

Browse files
EnqueueDuckEnqueueDuck
authored andcommitted
Remove unnecessary thread part
1 parent 608bcf4 commit 78d0718

File tree

6 files changed

+15
-163
lines changed

6 files changed

+15
-163
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Introduction
22

3-
This repository contains several versions of a HTTP Server implemented in CPP. The purpose
4-
is to compare performance of different implementations and shows how one can optimize the
5-
server to achieve beter through-put.
3+
A sample HTTP Server implemented using `libevent`.
4+
5+
This repository also contains several versions of a HTTP Server implemented in cpp.
66

77
# Releases
88

9-
To run the server, default host is 14396:
9+
To run the server, use the following command, default host is 14396:
1010

1111
```
1212
bazel run -c opt src/main/cpp:server
@@ -15,14 +15,14 @@ bazel run -c opt src/main/cpp:server
1515
### Version 3.1.0
1616

1717
The base class for server is `ServerSocket` at `src/main/cpp/server_socket.h`. I use an
18-
`evconnlistener` from `libevent` to bind and listen on the server address. For a new connection
19-
accepted, `accept_conn_cb` is called. The server passes the connection to one of the workers
20-
(defined in `src/main/cpp/server`);
21-
22-
The server worker runs an event loop, connections received from the server will be added for
23-
monitoring. When the connection becomes active, `conn_read_callback` will be triggered. It reads
24-
from the socket, parses the HTTP request, call `HandleHttpRequest` to produce an `HttpResponse` and
25-
write the response to the connection socket.
18+
`evconnlistener` from `libevent` to bind and listen on the server address. For each new connection
19+
, `accept_conn_cb` is called. The server passes the connection to one of the workers to handle
20+
(defined in `src/main/cpp/server`).
21+
22+
The server worker runs an event loop, connections received from the server will be added to the
23+
loop for monitoring. When the connection becomes active, `conn_read_callback` will be triggered. It
24+
reads from the socket, parses the HTTP request, call `HandleHttpRequest` to produce an
25+
`HttpResponse` and write the response to the connection socket.
2626

2727
Some notes:
2828
- Connections received from `evconnlistener` are non-blocking by default. When reading from

src/main/cpp/BUILD

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,11 @@ cc_library(
1111
includes = ["."],
1212
copts = ["-std=c++1z"],
1313
deps = [
14-
":thread",
1514
"@third_party-event//:event",
1615
"@third_party-glog//:glog",
1716
]
1817
)
1918

20-
cc_library(
21-
name = "thread",
22-
srcs = glob([
23-
"thread/*.cpp",
24-
]),
25-
hdrs = glob([
26-
"thread/*.h",
27-
]),
28-
includes = ["."],
29-
deps = [
30-
"@third_party-glog//:glog",
31-
]
32-
)
33-
3419
cc_binary(
3520
name = "server",
3621
srcs = ["main.cpp"],

src/main/cpp/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55

66
#include "http/server.h"
77

8+
DEFINE_int32(port, 14396, "Server port");
9+
810
int main(int argc, char *argv[]) {
911
FLAGS_logtostderr = 1;
1012
google::InitGoogleLogging(argv[0]);
1113
google::ParseCommandLineFlags(&argc, &argv, true);
1214

1315
http::ServerOpts opts;
1416
opts.num_workers = std::thread::hardware_concurrency();
17+
opts.socket_opts.port = FLAGS_port;
1518

1619
http::Server server(opts);
1720
server.Initialize();

src/main/cpp/tests/test_thread.cpp

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/cpp/thread/executor.cpp

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/main/cpp/thread/executor.h

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)