mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-28 12:40:54 +00:00
Performance improvement!
This commit is contained in:
1 parent
c53d93d145
commit
f29bb15f9d
4 files changed
+10815
-11336
No files matched your search
+8
-5
@@ -1,4 +1,7 @@
|
|||||||
CXXFLAGS = -std=c++11 -O2 -I..
|
CXXFLAGS = -O2 -I..
|
||||||
|
|
||||||
|
CPPHTTPLIB_CXXFLAGS = -std=c++11
|
||||||
|
CROW_CXXFLAGS = -std=c++17
|
||||||
|
|
||||||
CPPHTTPLIB_FLAGS = -DCPPHTTPLIB_THREAD_POOL_COUNT=16
|
CPPHTTPLIB_FLAGS = -DCPPHTTPLIB_THREAD_POOL_COUNT=16
|
||||||
|
|
||||||
@@ -18,11 +21,11 @@ run : server
|
|||||||
@./server
|
@./server
|
||||||
|
|
||||||
server : cpp-httplib/main.cpp ../httplib.h
|
server : cpp-httplib/main.cpp ../httplib.h
|
||||||
@g++ -o $@ $(CXXFLAGS) $(CPPHTTPLIB_FLAGS) cpp-httplib/main.cpp
|
@g++ -o $@ $(CXXFLAGS) $(CPPHTTPLIB_CXXFLAGS) $(CPPHTTPLIB_FLAGS) cpp-httplib/main.cpp
|
||||||
|
|
||||||
# crow
|
# crow
|
||||||
bench-crow: server-crow
|
bench-crow: server-crow
|
||||||
@echo "-------------\n Crow v1.2.0\n-------------\n"
|
@echo "-------------\n Crow v1.3.1\n-------------\n"
|
||||||
@./server-crow & export PID=$$!; $(BENCH); kill $${PID}
|
@./server-crow & export PID=$$!; $(BENCH); kill $${PID}
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
@@ -32,8 +35,8 @@ monitor-crow: server-crow
|
|||||||
run-crow : server-crow
|
run-crow : server-crow
|
||||||
@./server-crow
|
@./server-crow
|
||||||
|
|
||||||
server-crow : crow/main.cpp
|
server-crow : crow/main.cpp crow/crow_all.h
|
||||||
@g++ -o $@ $(CXXFLAGS) crow/main.cpp
|
@g++ -o $@ $(CXXFLAGS) $(CROW_CXXFLAGS) crow/main.cpp
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
build: server server-crow
|
build: server server-crow
|
||||||
|
|||||||
+10788
-11308
File diff suppressed because it is too large.
Load diff
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class CustomLogger : public crow::ILogHandler {
|
class CustomLogger : public crow::ILogHandler {
|
||||||
public:
|
public:
|
||||||
void log(std::string, crow::LogLevel) {}
|
void log(const std::string &, crow::LogLevel) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|||||||
@@ -9862,8 +9862,7 @@ inline bool SocketStream::wait_readable() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool SocketStream::wait_writable() const {
|
inline bool SocketStream::wait_writable() const {
|
||||||
return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0 &&
|
return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0;
|
||||||
is_socket_alive(sock_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ssize_t SocketStream::read(char *ptr, size_t size) {
|
inline ssize_t SocketStream::read(char *ptr, size_t size) {
|
||||||
@@ -10194,7 +10193,7 @@ inline bool SSLSocketStream::wait_readable() const {
|
|||||||
|
|
||||||
inline bool SSLSocketStream::wait_writable() const {
|
inline bool SSLSocketStream::wait_writable() const {
|
||||||
return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0 &&
|
return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0 &&
|
||||||
is_socket_alive(sock_) && !tls::is_peer_closed(session_, sock_);
|
!tls::is_peer_closed(session_, sock_);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
|
inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
|
||||||
@@ -10718,29 +10717,26 @@ inline bool Server::write_response_core(Stream &strm, bool close_connection,
|
|||||||
if (post_routing_handler_) { post_routing_handler_(req, res); }
|
if (post_routing_handler_) { post_routing_handler_(req, res); }
|
||||||
|
|
||||||
// Response line and headers
|
// Response line and headers
|
||||||
{
|
detail::BufferStream bstrm;
|
||||||
detail::BufferStream bstrm;
|
if (!detail::write_response_line(bstrm, res.status)) { return false; }
|
||||||
if (!detail::write_response_line(bstrm, res.status)) { return false; }
|
if (header_writer_(bstrm, res.headers) <= 0) { return false; }
|
||||||
if (header_writer_(bstrm, res.headers) <= 0) { return false; }
|
|
||||||
|
|
||||||
// Flush buffer
|
// Combine small body with headers to reduce write syscalls
|
||||||
auto &data = bstrm.get_buffer();
|
if (req.method != "HEAD" && !res.body.empty() && !res.content_provider_) {
|
||||||
detail::write_data(strm, data.data(), data.size());
|
bstrm.write(res.body.data(), res.body.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Body
|
// Flush buffer
|
||||||
|
auto &data = bstrm.get_buffer();
|
||||||
|
if (!detail::write_data(strm, data.data(), data.size())) { return false; }
|
||||||
|
|
||||||
|
// Streaming body
|
||||||
auto ret = true;
|
auto ret = true;
|
||||||
if (req.method != "HEAD") {
|
if (req.method != "HEAD" && res.content_provider_) {
|
||||||
if (!res.body.empty()) {
|
if (write_content_with_provider(strm, req, res, boundary, content_type)) {
|
||||||
if (!detail::write_data(strm, res.body.data(), res.body.size())) {
|
res.content_provider_success_ = true;
|
||||||
ret = false;
|
} else {
|
||||||
}
|
ret = false;
|
||||||
} else if (res.content_provider_) {
|
|
||||||
if (write_content_with_provider(strm, req, res, boundary, content_type)) {
|
|
||||||
res.content_provider_success_ = true;
|
|
||||||
} else {
|
|
||||||
ret = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user