namespace {
-/// @brief Maximum size of the HTTP message that can be logged.
+/// @brief Maximum size of a message that can be logged.
///
-/// The part of the HTTP message beyond this value is truncated.
-constexpr size_t MAX_LOGGED_MESSAGE_SIZE = 1024;
+/// The part of the message beyond this value is truncated.
+const size_t MAX_LOGGED_MESSAGE_SIZE = 1024;
}
// of the callback, because the underlying boost functions make copies
// as needed.
TcpConnectionAcceptorCallback cb = std::bind(&TcpConnection::acceptorCallback,
- shared_from_this(), ph::_1); // error
+ shared_from_this(), ph::_1);
try {
TlsConnectionAcceptorPtr tls_acceptor =
boost::dynamic_pointer_cast<TlsConnectionAcceptor>(acceptor_);
/// stored.
/// @param callback Callback invoked when new connection is accepted.
/// @param request_timeout Configured timeout for a TCP request.
- /// @param idle_timeout Timeout after which persistent TCP connection is
+ /// @param idle_timeout Timeout after which a TCP connection is
/// closed by the server.
/// @param read_max maximum size of a single socket read. Defaults to 32K.
TcpConnection(asiolink::IOService& io_service,
/// @param request Pointer to the request to be guarded by the timeout.
void setupRequestTimer(TcpRequestPtr request = TcpRequestPtr());
- /// @brief Reset timer for detecting idle timeout in persistent connections.
+ /// @brief Reset timer for detecting idle timeout in connections.
void setupIdleTimer();
/// @brief Callback invoked when the TCP Request Timeout occurs.
std::string getRemoteEndpointAddressAsText() const;
/// @brief Returns pointer to the first byte of the input buffer.
+ ///
+ /// @throw InvalidOperation if called when the buffer is empty.
unsigned char* getInputBufData() {
+ if (input_buf_.empty()) {
+ isc_throw(InvalidOperation, "TcpConnection::getInputBufData() - cannot access empty buffer");
+ }
+
return (input_buf_.data());
}
/// @brief TLS context.
asiolink::TlsContextPtr tls_context_;
- /// @brief Timeout after which the persistent TCP connection is shut
+ /// @brief Timeout after which the a TCP connection is shut
/// down by the server.
long idle_timeout_;
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef HTTP_ACCEPTOR_H
-#define HTTP_ACCEPTOR_H
+#ifndef TCP_CONNECTION_ACCEPTOR_H
+#define TCP_CONNECTION_ACCEPTOR_H
#include <asiolink/tcp_acceptor.h>
#include <asiolink/tls_acceptor.h>
<< request_timeout_);
}
- // Idle persistent connection timeout is signed and must be greater than 0.
+ // Idle connection timeout is signed and must be greater than 0.
if (idle_timeout_ <= 0) {
- isc_throw(TcpListenerError, "Invalid desired TCP idle persistent connection"
+ isc_throw(TcpListenerError, "Invalid desired TCP idle connection"
" timeout " << idle_timeout_);
}
}
isc::Exception(file, line, what) { };
};
-/// @brief ementation of the @ref TcpListener.
+/// @brief Implements a class that listens for, accepts, and manages
+/// TCP connections. It uses a multi-threaded connection pool, such
+/// that each connection does its client's work on it's own thread.
class TcpListener {
public:
/// @brief TCP request timeout value.
/// @param tls_context TLS context.
/// @param request_timeout Timeout maximum amount of time allotted for
/// a request to be processed.
- /// @param idle_timeout Timeout after which an idle persistent TCP
- /// connection is closed by the server.
+ /// @param idle_timeout Timeout after which an idle TCP connection is
+ /// closed by the server.
///
/// @throw TcpListenerError when any of the specified parameters is
/// invalid.
/// @brief Maximum amount of time request to be processed.
long request_timeout_;
- /// @brief Timeout after which idle persistent connection is closed by
+ /// @brief Timeout after which idle connection is closed by
/// the server.
long idle_timeout_;
};
This debug message is issued when a timeout occurs during the reception of request
% TCP_IDLE_CONNECTION_TIMEOUT_OCCURRED closing connection with %1 as a result of a timeout
-This debug message is issued when the persistent TCP connection is being
-closed as a result of being idle.
+This debug message is issued when the TCP connection is being closed as a
+result of being idle.
% TCP_PREMATURE_CONNECTION_TIMEOUT_OCCURRED premature connection timeout occurred: in transaction ? %1, transid: %2, current_transid: %3
This warning message is issued when unexpected timeout occurred during the
uint16_t len = ((unsigned int)(cp[0])) << 8;
len |= ((unsigned int)(cp[1]));
expected_size_ = len + sizeof(len);
- }
+ }
}
return (nbytes);
}
-std::string
+std::string
TcpStreamRequest::logFormatRequest(const size_t limit) const {
std::stringstream output;
try {
size_t max = (limit && (limit < wire_data_.size()) ? limit : wire_data_.size());
- output << "expected_size_: " << expected_size_ << ", current size: " << wire_data_.size()
- << ", data: "
+ output << "expected_size_: " << expected_size_ << ", current size: " << wire_data_.size()
+ << ", data: "
<< isc::util::str::dumpAsHex(wire_data_.data(), max);
} catch (const std::exception& ex) {
std::stringstream output;
request_ = std::string(wire_data_.begin() + sizeof(uint16_t) , wire_data_.end());
}
-void
+void
TcpStreamResponse::setResponseData(const std::string& response) {
response_ = response;
}
-void
+void
TcpStreamResponse::appendResponseData(const std::string& response) {
response_ += response;
}
-void
+void
TcpStreamResponse::pack() {
wire_data_.clear();
// Prepend the length of the request.