mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 09:43:51 +00:00
Code formating
This commit is contained in:
parent
226388ae27
commit
06026bb47d
84
httplib.h
84
httplib.h
@ -505,7 +505,7 @@ public:
|
|||||||
virtual void enqueue(std::function<void()> fn) = 0;
|
virtual void enqueue(std::function<void()> fn) = 0;
|
||||||
virtual void shutdown() = 0;
|
virtual void shutdown() = 0;
|
||||||
|
|
||||||
virtual void on_idle(){}
|
virtual void on_idle() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ThreadPool : public TaskQueue {
|
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,
|
time_t write_timeout_usec,
|
||||||
std::function<bool(Stream &)> callback);
|
std::function<bool(Stream &)> callback);
|
||||||
|
|
||||||
socket_t create_client_socket(const char *host, const char *ip, int port, int address_family,
|
socket_t create_client_socket(
|
||||||
|
const char *host, const char *ip, int port, int address_family,
|
||||||
bool tcp_nodelay, SocketOptions socket_options,
|
bool tcp_nodelay, SocketOptions socket_options,
|
||||||
time_t connection_timeout_sec,
|
time_t connection_timeout_sec, time_t connection_timeout_usec,
|
||||||
time_t connection_timeout_usec,
|
time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec,
|
||||||
time_t read_timeout_sec, time_t read_timeout_usec,
|
time_t write_timeout_usec, const std::string &intf, Error &error);
|
||||||
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,
|
const char *get_header_value(const Headers &headers, const char *key,
|
||||||
size_t id = 0, const char *def = nullptr);
|
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 handle_EINTR([&]() {
|
||||||
return recv(sock,
|
return recv(sock,
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static_cast<char *>(ptr),
|
static_cast<char *>(ptr), static_cast<int>(size),
|
||||||
static_cast<int>(size),
|
|
||||||
#else
|
#else
|
||||||
ptr,
|
ptr, size,
|
||||||
size,
|
|
||||||
#endif
|
#endif
|
||||||
flags);
|
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 handle_EINTR([&]() {
|
||||||
return send(sock,
|
return send(sock,
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static_cast<const char *>(ptr),
|
static_cast<const char *>(ptr), static_cast<int>(size),
|
||||||
static_cast<int>(size),
|
|
||||||
#else
|
#else
|
||||||
ptr,
|
ptr, size,
|
||||||
size,
|
|
||||||
#endif
|
#endif
|
||||||
flags);
|
flags);
|
||||||
});
|
});
|
||||||
@ -2460,8 +2455,8 @@ inline int shutdown_socket(socket_t sock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename BindOrConnect>
|
template <typename BindOrConnect>
|
||||||
socket_t create_socket(const char *host, const char *ip, int port, int address_family,
|
socket_t create_socket(const char *host, const char *ip, int port,
|
||||||
int socket_flags, bool tcp_nodelay,
|
int address_family, int socket_flags, bool tcp_nodelay,
|
||||||
SocketOptions socket_options,
|
SocketOptions socket_options,
|
||||||
BindOrConnect bind_or_connect) {
|
BindOrConnect bind_or_connect) {
|
||||||
// Get address info
|
// 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;
|
hints.ai_protocol = 0;
|
||||||
|
|
||||||
// Ask getaddrinfo to convert IP in c-string to address
|
// 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_family = AF_UNSPEC;
|
||||||
hints.ai_flags = AI_NUMERICHOST;
|
hints.ai_flags = AI_NUMERICHOST;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto service = std::to_string(port);
|
auto service = std::to_string(port);
|
||||||
|
|
||||||
if (ip[0] != '\0' ?
|
if (ip[0] != '\0' ? getaddrinfo(ip, service.c_str(), &hints, &result)
|
||||||
getaddrinfo(ip, service.c_str(), &hints, &result) :
|
: getaddrinfo(host, service.c_str(), &hints, &result)) {
|
||||||
getaddrinfo(host, service.c_str(), &hints, &result)) {
|
|
||||||
#if defined __linux__ && !defined __ANDROID__
|
#if defined __linux__ && !defined __ANDROID__
|
||||||
res_init();
|
res_init();
|
||||||
#endif
|
#endif
|
||||||
@ -2619,10 +2613,10 @@ inline std::string if2ip(const std::string &ifn) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline socket_t create_client_socket(
|
inline socket_t create_client_socket(
|
||||||
const char *host, const char *ip, int port, int address_family, bool tcp_nodelay,
|
const char *host, const char *ip, int port, int address_family,
|
||||||
SocketOptions socket_options, time_t connection_timeout_sec,
|
bool tcp_nodelay, SocketOptions socket_options,
|
||||||
time_t connection_timeout_usec, time_t read_timeout_sec,
|
time_t connection_timeout_sec, time_t connection_timeout_usec,
|
||||||
time_t read_timeout_usec, time_t write_timeout_sec,
|
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) {
|
time_t write_timeout_usec, const std::string &intf, Error &error) {
|
||||||
auto sock = create_socket(
|
auto sock = create_socket(
|
||||||
host, ip, port, address_family, 0, tcp_nodelay, std::move(socket_options),
|
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);
|
ret = inflate(&strm_, Z_NO_FLUSH);
|
||||||
|
|
||||||
if (prev_avail_in - strm_.avail_in == 0) {
|
if (prev_avail_in - strm_.avail_in == 0) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(ret != Z_STREAM_ERROR);
|
assert(ret != Z_STREAM_ERROR);
|
||||||
switch (ret) {
|
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),
|
: sock_(sock), read_timeout_sec_(read_timeout_sec),
|
||||||
read_timeout_usec_(read_timeout_usec),
|
read_timeout_usec_(read_timeout_usec),
|
||||||
write_timeout_sec_(write_timeout_sec),
|
write_timeout_sec_(write_timeout_sec),
|
||||||
write_timeout_usec_(write_timeout_usec),
|
write_timeout_usec_(write_timeout_usec), read_buff_(read_buff_size_, 0) {}
|
||||||
read_buff_(read_buff_size_, 0) {}
|
|
||||||
|
|
||||||
inline SocketStream::~SocketStream() {}
|
inline SocketStream::~SocketStream() {}
|
||||||
|
|
||||||
@ -4457,9 +4448,11 @@ inline bool SocketStream::is_writable() const {
|
|||||||
|
|
||||||
inline ssize_t SocketStream::read(char *ptr, size_t size) {
|
inline ssize_t SocketStream::read(char *ptr, size_t size) {
|
||||||
#ifdef _WIN32
|
#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
|
#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
|
#endif
|
||||||
|
|
||||||
if (read_buff_off_ < read_buff_content_size_) {
|
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;
|
read_buff_content_size_ = 0;
|
||||||
|
|
||||||
if (size < read_buff_size_) {
|
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) {
|
if (n <= 0) {
|
||||||
return n;
|
return n;
|
||||||
} else if (n <= static_cast<ssize_t>(size)) {
|
} 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; }
|
if (!is_writable()) { return -1; }
|
||||||
|
|
||||||
#ifdef _WIN32
|
#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
|
#endif
|
||||||
|
|
||||||
return send_socket(sock_, ptr, size, CPPHTTPLIB_SEND_FLAGS);
|
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_
|
// Check is custom IP specified for host_
|
||||||
std::string ip;
|
std::string ip;
|
||||||
auto it = addr_map_.find(host_);
|
auto it = addr_map_.find(host_);
|
||||||
if(it != addr_map_.end())
|
if (it != addr_map_.end()) ip = it->second;
|
||||||
ip = it->second;
|
|
||||||
|
|
||||||
return detail::create_client_socket(
|
return detail::create_client_socket(
|
||||||
host_.c_str(), ip.c_str(), port_, address_family_, tcp_nodelay_, socket_options_,
|
host_.c_str(), ip.c_str(), port_, address_family_, tcp_nodelay_,
|
||||||
connection_timeout_sec_, connection_timeout_usec_, read_timeout_sec_,
|
socket_options_, connection_timeout_sec_, connection_timeout_usec_,
|
||||||
read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, interface_,
|
read_timeout_sec_, read_timeout_usec_, write_timeout_sec_,
|
||||||
error);
|
write_timeout_usec_, interface_, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool ClientImpl::create_and_connect_socket(Socket &socket,
|
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_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);
|
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::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));
|
cli_->set_hostname_addr_map(std::move(addr_map));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user