Allow to set buffer size for client; don't auto adjust reading buffer size; refine the global definitions.
This commit is contained in:
+21
-3
@@ -9,9 +9,8 @@
|
||||
|
||||
namespace webcc {
|
||||
|
||||
// Adjust buffer size according to content length.
|
||||
// This is to avoid reading too many times.
|
||||
void AdjustBufferSize(std::size_t content_length, std::vector<char>* buffer);
|
||||
// If |port| is empty, try to extract it from |host| (separated by ':').
|
||||
void AdjustHostPort(std::string& host, std::string& port);
|
||||
|
||||
void PrintEndpoint(std::ostream& ostream,
|
||||
const boost::asio::ip::tcp::endpoint& endpoint);
|
||||
@@ -27,6 +26,25 @@ std::string EndpointToString(const boost::asio::ip::tcp::endpoint& endpoint);
|
||||
// See: https://tools.ietf.org/html/rfc7231#section-7.1.1.2
|
||||
std::string GetHttpDateTimestamp();
|
||||
|
||||
// Resize a buffer in ctor and restore its original size in dtor.
|
||||
struct BufferResizer {
|
||||
BufferResizer(std::vector<char>* buffer, std::size_t new_size)
|
||||
: buffer_(buffer), old_size_(buffer->size()) {
|
||||
if (new_size != 0 && new_size != old_size_) {
|
||||
buffer_->resize(new_size);
|
||||
}
|
||||
}
|
||||
|
||||
~BufferResizer() {
|
||||
if (buffer_->size() != old_size_) {
|
||||
buffer_->resize(old_size_);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<char>* buffer_;
|
||||
std::size_t old_size_;
|
||||
};
|
||||
|
||||
} // namespace webcc
|
||||
|
||||
#endif // WEBCC_UTILITY_H_
|
||||
|
||||
Reference in New Issue
Block a user