Fixed the small stuff.
acceptor_callback_(callback),
input_buf_(read_max) {
if (!tls_context) {
- HERE("");
tcp_socket_.reset(new asiolink::TCPSocket<SocketCallback>(io_service));
} else {
tls_socket_.reset(new asiolink::TLSSocket<SocketCallback>(io_service,
}
TcpConnection::~TcpConnection() {
- HERE("");
close();
}
// of the callback, because the underlying boost functions make copies
// as needed.
TcpConnectionAcceptorCallback cb = std::bind(&TcpConnection::acceptorCallback,
- shared_from_this(), ph::_1);
+ shared_from_this(),
+ ph::_1);
try {
TlsConnectionAcceptorPtr tls_acceptor =
boost::dynamic_pointer_cast<TlsConnectionAcceptor>(acceptor_);
if (!tcp_socket_) {
isc_throw(Unexpected, "internal error: TCP socket is null");
}
- HERE("");
acceptor_->asyncAccept(*tcp_socket_, cb);
} else {
if (!tls_socket_) {
TcpConnection::doHandshake() {
// Skip the handshake if the socket is not a TLS one.
if (!tls_socket_) {
- HERE("");
doRead();
return;
}
- HERE("setupIdleTimer");
setupIdleTimer();
// Create instance of the callback. It is safe to pass the local instance
void
TcpConnection::doRead(TcpRequestPtr request) {
try {
- HERE("");
TCPEndpoint endpoint;
- HERE("setup Idle timer");
setupIdleTimer();
// Request hasn't been created if we are starting to read the
ph::_1, // error
ph::_2)); // bytes_transferred
if (tcp_socket_) {
- HERE("tcp_socket read max bytes:" << getInputBufSize());
tcp_socket_->asyncReceive(static_cast<void*>(getInputBufData()),
getInputBufSize(), 0, &endpoint, cb);
return;
}
if (tls_socket_) {
- HERE("tls_socket read max bytes:" << getInputBufSize());
tls_socket_->asyncReceive(static_cast<void*>(getInputBufData()),
getInputBufSize(), 0, &endpoint, cb);
return;
TcpConnection::doWrite(TcpResponsePtr response) {
try {
if (response->wireDataAvail()) {
- HERE("send:" << isc::util::str::dumpAsHex(response->getWireData(), response->getWireDataSize()));
// Create instance of the callback. It is safe to pass the local instance
// of the callback, because the underlying std functions make copies
// as needed.
}
} else {
// The connection remains open and we are done sending the response.
- HERE("setupIdleTimer - write finsihed");
setupIdleTimer();
}
} catch (...) {
void
TcpConnection::asyncSendResponse(TcpResponsePtr response) {
- HERE("");
doWrite(response);
}
TCP_REQUEST_RECEIVE_START)
.arg(getRemoteEndpointAddressAsText());
- HERE("");
doRead();
}
}
}
// Data received, Restart the request timer.
- HERE("setupIdleTimer - data recevied, post it")
setupIdleTimer();
TcpRequestPtr next_request = request;
.arg(getRemoteEndpointAddressAsText());
// Request complete, stop the timer.
- HERE("Cancel idleTimer while we handle complete request");
idle_timer_.cancel();
// Process the completed request.
LOG_DEBUG(tcp_logger, isc::log::DBGLVL_TRACE_DETAIL,
TCP_IDLE_CONNECTION_TIMEOUT_OCCURRED)
.arg(getRemoteEndpointAddressAsText());
- HERE("idle timeout! shutting down");
// In theory we should shutdown first and stop/close after but
// it is better to put the connection management responsibility
// on the client... so simply drop idle connections.
namespace tcp {
/// @todo Take this out, it's just for dev coding
-#if 0
#define HERE(a) std::cout << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << " " << a << std::endl << std::flush;
-#else
-#define HERE(a)
-#endif
/// @brief Defines a data structure for storing raw bytes of data on the wire.
typedef std::vector<uint8_t> WireData;
/// @return Constant raw pointer to the data.
const uint8_t* getWireData() const {
if (wire_data_.empty()) {
- isc_throw(InvalidOperation, "TcpMessage::geWireData() - cannot access empty wire data");
+ isc_throw(InvalidOperation, "TcpMessage::getWireData() - cannot access empty wire data");
}
return (wire_data_.data());
};
/// @brief Abstract class used to receive an inbound message.
-class TcpRequest : public TcpMessage{
+class TcpRequest : public TcpMessage {
public:
/// @brief Constructor.
TcpRequest(){};
typedef boost::shared_ptr<TcpRequest> TcpRequestPtr;
/// @brief Abstract class used to create and send an outbound response.
-class TcpResponse : public TcpMessage{
+class TcpResponse : public TcpMessage {
public:
/// @brief Constructor
TcpResponse()
bool
TcpStreamRequest::needData() const {
- HERE("");
return (!expected_size_ || (wire_data_.size() < expected_size_));
}
size_t
TcpStreamRequest::postBuffer(const void* buf, const size_t nbytes) {
- HERE("");
if (nbytes) {
const char* bufptr = static_cast<const char*>(buf);
wire_data_.insert(wire_data_.end(), bufptr, bufptr + nbytes);
run_unittests_SOURCES += tcp_listener_unittests.cc
run_unittests_SOURCES += tcp_test_client.h
+# @todo These tests will be needed. These are here as a reminder.
#if HAVE_OPENSSL
#run_unittests_SOURCES += tls_unittest.cc
#run_unittests_SOURCES += tls_acceptor_unittest.cc
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
+#include <log/logger_support.h>
#include <gtest/gtest.h>
-#include <util/unittests/run_all.h>
-#include <log/logger_manager.h>
int
-main(int argc, char* argv[])
-{
- ::testing::InitGoogleTest(&argc, argv); // Initialize Google test
- isc::log::LoggerManager::init("unittest"); // Set a root logger name
- return (isc::util::unittests::run_all());
+main(int argc, char* argv[]) {
+ ::testing::InitGoogleTest(&argc, argv);
+ isc::log::initLogger();
+
+ int result = RUN_ALL_TESTS();
+
+ return (result);
}
TcpTestClientPtr client = *clients_.begin();
ASSERT_TRUE(client);
- // Tell the client expecting readingo to fail with an EOF.
+ // Tell the client expecting reading to fail with an EOF.
ASSERT_NO_THROW(client->waitForEof());
// Run until idle timer expires.
} else if (ec.value() == boost::asio::error::eof && expect_eof) {
expected_eof_ = true;
done_callback_();
+ return;
} else {
// Error occurred, bail...
ADD_FAILURE() << "error occurred while receiving TCP"
" response from the server: " << ec.message();
done_callback_();
+ return;
}
}
if (response.find("good bye", 0) != std::string::npos) {
receive_done_ = true;
done_callback_();
+ return;
}
// Clear out for the next one.
return (impl_->scrub(original));
}
-std::string dumpAsHex(const uint8_t* data, size_t len) {
+std::string dumpAsHex(const uint8_t* data, size_t length) {
std::stringstream output;
for (unsigned int i = 0; i < len; i++) {
if (i) {
/// @param data pointer to the data to dump
/// @param length number of bytes to dump. Caller should ensure the length
/// does not exceed the buffer.
-std::string dumpAsHex(const uint8_t* data, size_t len);
+std::string dumpAsHex(const uint8_t* data, size_t length);
} // namespace str
} // namespace util