Code formating

This commit is contained in:
yhirose 2021-11-23 10:53:05 -05:00
parent 226388ae27
commit 06026bb47d

View file

@ -505,7 +505,7 @@ public:
virtual void enqueue(std::function<void()> fn) = 0;
virtual void shutdown() = 0;
virtual void on_idle(){}
virtual void on_idle() {}
};
class ThreadPool : public TaskQueue {
@ -1663,14 +1663,12 @@ bool process_client_socket(socket_t sock, time_t read_timeout_sec,
time_t write_timeout_usec,
std::function<bool(Stream &)> callback);
socket_t create_client_socket(const char *host, const char *ip, int port, int address_family,
bool tcp_nodelay, SocketOptions socket_options,
time_t connection_timeout_sec,
time_t connection_timeout_usec,
time_t read_timeout_sec, time_t read_timeout_usec,
time_t write_timeout_sec,
time_t write_timeout_usec,
const std::string &intf, Error &error);
socket_t create_client_socket(
const char *host, const char *ip, int port, int address_family,
bool tcp_nodelay, SocketOptions socket_options,
time_t connection_timeout_sec, time_t connection_timeout_usec,
time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec,
time_t write_timeout_usec, const std::string &intf, Error &error);
const char *get_header_value(const Headers &headers, const char *key,
size_t id = 0, const char *def = nullptr);
@ -2209,25 +2207,22 @@ inline ssize_t read_socket(socket_t sock, void *ptr, size_t size, int flags) {
return handle_EINTR([&]() {
return recv(sock,
#ifdef _WIN32
static_cast<char *>(ptr),
static_cast<int>(size),
static_cast<char *>(ptr), static_cast<int>(size),
#else
ptr,
size,
ptr, size,
#endif
flags);
});
}
inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size, int flags) {
inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size,
int flags) {
return handle_EINTR([&]() {
return send(sock,
#ifdef _WIN32
static_cast<const char *>(ptr),
static_cast<int>(size),
static_cast<const char *>(ptr), static_cast<int>(size),
#else
ptr,
size,
ptr, size,
#endif
flags);
});
@ -2460,8 +2455,8 @@ inline int shutdown_socket(socket_t sock) {
}
template <typename BindOrConnect>
socket_t create_socket(const char *host, const char *ip, int port, int address_family,
int socket_flags, bool tcp_nodelay,
socket_t create_socket(const char *host, const char *ip, int port,
int address_family, int socket_flags, bool tcp_nodelay,
SocketOptions socket_options,
BindOrConnect bind_or_connect) {
// Get address info
@ -2475,16 +2470,15 @@ socket_t create_socket(const char *host, const char *ip, int port, int address_f
hints.ai_protocol = 0;
// Ask getaddrinfo to convert IP in c-string to address
if(ip[0] != '\0') {
if (ip[0] != '\0') {
hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_NUMERICHOST;
}
auto service = std::to_string(port);
if (ip[0] != '\0' ?
getaddrinfo(ip, service.c_str(), &hints, &result) :
getaddrinfo(host, service.c_str(), &hints, &result)) {
if (ip[0] != '\0' ? getaddrinfo(ip, service.c_str(), &hints, &result)
: getaddrinfo(host, service.c_str(), &hints, &result)) {
#if defined __linux__ && !defined __ANDROID__
res_init();
#endif
@ -2619,10 +2613,10 @@ inline std::string if2ip(const std::string &ifn) {
#endif
inline socket_t create_client_socket(
const char *host, const char *ip, int port, int address_family, bool tcp_nodelay,
SocketOptions socket_options, time_t connection_timeout_sec,
time_t connection_timeout_usec, time_t read_timeout_sec,
time_t read_timeout_usec, time_t write_timeout_sec,
const char *host, const char *ip, int port, int address_family,
bool tcp_nodelay, SocketOptions socket_options,
time_t connection_timeout_sec, time_t connection_timeout_usec,
time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec,
time_t write_timeout_usec, const std::string &intf, Error &error) {
auto sock = create_socket(
host, ip, port, address_family, 0, tcp_nodelay, std::move(socket_options),
@ -2996,9 +2990,7 @@ inline bool gzip_decompressor::decompress(const char *data, size_t data_length,
ret = inflate(&strm_, Z_NO_FLUSH);
if (prev_avail_in - strm_.avail_in == 0) {
return false;
}
if (prev_avail_in - strm_.avail_in == 0) { return false; }
assert(ret != Z_STREAM_ERROR);
switch (ret) {
@ -4442,8 +4434,7 @@ inline SocketStream::SocketStream(socket_t sock, time_t read_timeout_sec,
: sock_(sock), read_timeout_sec_(read_timeout_sec),
read_timeout_usec_(read_timeout_usec),
write_timeout_sec_(write_timeout_sec),
write_timeout_usec_(write_timeout_usec),
read_buff_(read_buff_size_, 0) {}
write_timeout_usec_(write_timeout_usec), read_buff_(read_buff_size_, 0) {}
inline SocketStream::~SocketStream() {}
@ -4457,9 +4448,11 @@ inline bool SocketStream::is_writable() const {
inline ssize_t SocketStream::read(char *ptr, size_t size) {
#ifdef _WIN32
size = (std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));
size =
(std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));
#else
size = (std::min)(size, static_cast<size_t>((std::numeric_limits<ssize_t>::max)()));
size = (std::min)(size,
static_cast<size_t>((std::numeric_limits<ssize_t>::max)()));
#endif
if (read_buff_off_ < read_buff_content_size_) {
@ -4481,7 +4474,8 @@ inline ssize_t SocketStream::read(char *ptr, size_t size) {
read_buff_content_size_ = 0;
if (size < read_buff_size_) {
auto n = read_socket(sock_, read_buff_.data(), read_buff_size_, CPPHTTPLIB_RECV_FLAGS);
auto n = read_socket(sock_, read_buff_.data(), read_buff_size_,
CPPHTTPLIB_RECV_FLAGS);
if (n <= 0) {
return n;
} else if (n <= static_cast<ssize_t>(size)) {
@ -4502,7 +4496,8 @@ inline ssize_t SocketStream::write(const char *ptr, size_t size) {
if (!is_writable()) { return -1; }
#ifdef _WIN32
size = (std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));
size =
(std::min)(size, static_cast<size_t>((std::numeric_limits<int>::max)()));
#endif
return send_socket(sock_, ptr, size, CPPHTTPLIB_SEND_FLAGS);
@ -5634,14 +5629,13 @@ inline socket_t ClientImpl::create_client_socket(Error &error) const {
// Check is custom IP specified for host_
std::string ip;
auto it = addr_map_.find(host_);
if(it != addr_map_.end())
ip = it->second;
if (it != addr_map_.end()) ip = it->second;
return detail::create_client_socket(
host_.c_str(), ip.c_str(), port_, address_family_, tcp_nodelay_, socket_options_,
connection_timeout_sec_, connection_timeout_usec_, read_timeout_sec_,
read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, interface_,
error);
host_.c_str(), ip.c_str(), port_, address_family_, tcp_nodelay_,
socket_options_, connection_timeout_sec_, connection_timeout_usec_,
read_timeout_sec_, read_timeout_usec_, write_timeout_sec_,
write_timeout_usec_, interface_, error);
}
inline bool ClientImpl::create_and_connect_socket(Socket &socket,
@ -6766,7 +6760,8 @@ inline void ClientImpl::set_follow_location(bool on) { follow_location_ = on; }
inline void ClientImpl::set_url_encode(bool on) { url_encode_ = on; }
inline void ClientImpl::set_hostname_addr_map(const std::map<std::string, std::string> addr_map) {
inline void ClientImpl::set_hostname_addr_map(
const std::map<std::string, std::string> addr_map) {
addr_map_ = std::move(addr_map);
}
@ -7895,7 +7890,8 @@ inline size_t Client::is_socket_open() const { return cli_->is_socket_open(); }
inline void Client::stop() { cli_->stop(); }
inline void Client::set_hostname_addr_map(const std::map<std::string, std::string> addr_map) {
inline void Client::set_hostname_addr_map(
const std::map<std::string, std::string> addr_map) {
cli_->set_hostname_addr_map(std::move(addr_map));
}