Commit 7c419681 authored by Stephen Morris's avatar Stephen Morris

[trac499] Mischellaneous minor preparator changes

* Extend logging in IOFetch (and add message definitions)
* Update buffer size setting for UDP socket
* remove spaces at end of lines in other files
parent f0dd8824
......@@ -50,7 +50,8 @@ if USE_CLANGPP
libasiolink_la_CXXFLAGS += -Wno-error
endif
libasiolink_la_CPPFLAGS = $(AM_CPPFLAGS)
libasiolink_la_LIBADD = $(top_builddir)/src/lib/log/liblog.la
libasiolink_la_LIBADD =
libasiolink_la_LIBADD += $(top_builddir)/src/lib/resolve/libresolve.la
libasiolink_la_LIBADD += $(top_builddir)/src/lib/cache/libcache.la
libasiolink_la_LIBADD += $(top_builddir)/src/lib/nsas/libnsas.la
libasiolink_la_LIBADD += $(top_builddir)/src/lib/log/liblog.la
// File created from asiodef.msg on Thu Feb 24 11:52:42 2011
#include <cstddef>
#include <log/message_types.h>
#include <log/message_initializer.h>
namespace asiolink {
extern const isc::log::MessageID ASIO_FETCHCOMP = "FETCHCOMP";
extern const isc::log::MessageID ASIO_FETCHSTOP = "FETCHSTOP";
extern const isc::log::MessageID ASIO_OPENSOCK = "OPENSOCK";
extern const isc::log::MessageID ASIO_RECVSOCK = "RECVSOCK";
extern const isc::log::MessageID ASIO_RECVTMO = "RECVTMO";
extern const isc::log::MessageID ASIO_SENDSOCK = "SENDSOCK";
extern const isc::log::MessageID ASIO_UNKORIGIN = "UNKORIGIN";
extern const isc::log::MessageID ASIO_UNKRESULT = "UNKRESULT";
} // namespace asiolink
namespace {
const char* values[] = {
"FETCHCOMP", "upstream fetch to %s has now completed",
"FETCHSTOP", "upstream fetch to %s has been stopped",
"OPENSOCK", "error %d opening %s socket to %s",
"RECVSOCK", "error %d reading data from %s via a %s socket",
"RECVTMO", "receive timeout while waiting for data from %s",
"SENDSOCK", "error %d sending data to %s via a %s socket",
"UNKORIGIN", "unknown origin for ASIO error code %d (protocol: %s, address %s)",
"UNKRESULT", "unknown result (%d) when IOFetch::stop() was executed for I/O to %s",
NULL
};
const isc::log::MessageInitializer initializer(values);
} // Anonymous namespace
// File created from asiodef.msg on Thu Feb 24 11:52:42 2011
#ifndef __ASIODEF_H
#define __ASIODEF_H
#include <log/message_types.h>
namespace asiolink {
extern const isc::log::MessageID ASIO_FETCHCOMP;
extern const isc::log::MessageID ASIO_FETCHSTOP;
extern const isc::log::MessageID ASIO_OPENSOCK;
extern const isc::log::MessageID ASIO_RECVSOCK;
extern const isc::log::MessageID ASIO_RECVTMO;
extern const isc::log::MessageID ASIO_SENDSOCK;
extern const isc::log::MessageID ASIO_UNKORIGIN;
extern const isc::log::MessageID ASIO_UNKRESULT;
} // namespace asiolink
#endif // __ASIODEF_H
# Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
$PREFIX ASIO_
$NAMESPACE asiolink
FETCHCOMP upstream fetch to %s has now completed
+ A debug message, this records the the upstream fetch (a query made by the
+ resolver on behalf of its client) to the specified address has completed.
FETCHSTOP upstream fetch to %s has been stopped
+ An external component has requested the halting of an upstream fetch. This
+ is an allowed operation, and the message should only appear if debug is
+ enabled.
OPENSOCK error %d opening %s socket to %s
+ The asynchronous I/O code encountered an error when trying to open a socket
+ of the specified protocol in order to send a message to the target address.
+ The the number of the system error that cause the problem is given in the
+ message.
RECVSOCK error %d reading data from %s via a %s socket
+ The asynchronous I/O code encountered an error when trying read data from
+ the specified address on the given protocol. The the number of the system
+ error that cause the problem is given in the message.
SENDSOCK error %d sending data to %s via a %s socket
+ The asynchronous I/O code encountered an error when trying send data to
+ the specified address on the given protocol. The the number of the system
+ error that cause the problem is given in the message.
RECVTMO receive timeout while waiting for data from %s
+ An upstream fetch from the specified address timed out. This may happen for
+ any number of reasons and is most probably a problem at the remote server
+ or a problem on the network. The message will only appear if debug is
+ enabled.
UNKORIGIN unknown origin for ASIO error code %d (protocol: %s, address %s)
+ This message should not appear and indicates an internal error if it does.
+ Please enter a bug report.
UNKRESULT unknown result (%d) when IOFetch::stop() was executed for I/O to %s
+ The termination method of the resolver's upstream fetch class was called with
+ an unknown result code (which is given in the message). This message should
+ not appear and may indicate an internal error. Please enter a bug report.
......@@ -85,7 +85,3 @@
/// http://think-async.com/Asio/asio-1.3.1/doc/asio/reference/asio_handler_allocate.html
#endif // __ASIOLINK_H
\ No newline at end of file
// Local Variables:
// mode: c++
// End:
......@@ -26,13 +26,13 @@ class DNSLookup;
class DNSAnswer;
class DNSServiceImpl;
/// \brief Handle DNS Queries
///
/// DNSService is the service that handles DNS queries and answers with
/// a given IOService. This class is mainly intended to hold all the
/// logic that is shared between the authoritative and the recursive
/// server implementations. As such, it handles asio, including config
/// updates (through the 'Checkinprovider'), and listening sockets.
///
class DNSService {
///
/// \name Constructors and Destructor
......
......@@ -121,7 +121,3 @@ private:
} // asiolink
#endif // __IO_ADDRESS_H
\ No newline at end of file
// Local Variables:
// mode: c++
// End:
......@@ -41,7 +41,14 @@ public:
IOError(file, line, what) {}
};
/// \brief Socket not open
///
/// Thrown if attempt to change socket options fails.
class SocketSetError : public IOError {
public:
SocketSetError(const char* file, size_t line, const char* what) :
IOError(file, line, what) {}
};
/// Forward declaration of an IOEndpoint
class IOEndpoint;
......@@ -276,7 +283,9 @@ public:
/// \param cumulative Unused
/// \param endpoint Unused
/// \param callback Unused
virtual void asyncReceive(void* data, size_t, size_t, IOEndpoint*, C&) { }
virtual void asyncReceive(void* data, size_t, size_t, IOEndpoint*, C&) {
}
/// \brief Checks if the data received is complete.
///
/// \param data Unused
......
......@@ -116,7 +116,3 @@ public:
} // asiolink
#endif // __IO_ENDPOINT_H
\ No newline at end of file
// Local Variables:
// mode: c++
// End:
......@@ -46,7 +46,7 @@ isc::log::Logger logger("asio");
/// IOFetch Constructor - just initialize the private data
IOFetch::IOFetch(int protocol, IOService& service,
IOFetch::IOFetch(Protocol protocol, IOService& service,
const isc::dns::Question& question, const IOAddress& address, uint16_t port,
isc::dns::OutputBufferPtr& buff, Callback* cb, int wait)
:
......@@ -140,6 +140,7 @@ IOFetch::operator()(error_code ec, size_t length) {
data_->buffer->writeData(data_->data.get(), length);
// Finished with this socket, so close it.
data_->origin = CLOSE;
data_->socket->close();
/// We are done
......@@ -170,9 +171,14 @@ IOFetch::stop(Result result) {
// variable should be done inside a mutex (and the stopped_ variable
// declared as "volatile").
//
// The numeric arguments indicate the debug level, with the lower
// numbers indicating the most important information. The relative
// values are somewhat arbitrary.
//
// Although Logger::debug checks the debug flag internally, doing it
// in below avoids the overhead of a string conversion in the common
// case when debug is not enabled.
// below before calling Logger::debug avoids the overhead of a string
// conversion in the common paths and in the common case when debug is
// not enabled.
//
// TODO: Update testing of stopped_ if threads are used.
data_->stopped = true;
......@@ -185,15 +191,24 @@ IOFetch::stop(Result result) {
}
break;
case STOPPED:
case SUCCESS:
if (logger.isDebugEnabled(50)) {
logger.debug(50, ASIO_FETCOMP,
logger.debug(50, ASIO_FETCHCOMP,
data_->remote->getAddress().toText().c_str());
}
break;
case STOPPED:
// Fetch has been stopped for some other reason. This is
// allowed but as it is unusual it is logged, but with a lower
// debug level than a timeout (which is totally normal).
logger.debug(10, ASIO_FETCHSTOP,
data_->remote->getAddress().toText().c_str());
break;
default:
logger.error(ASIO_UNKRESULT, static_cast<int>(result));
logger.error(ASIO_UNKRESULT, static_cast<int>(result),
data_->remote->getAddress().toText().c_str());
}
// Stop requested, cancel and I/O's on the socket and shut it down,
......
......@@ -51,6 +51,12 @@ namespace asiolink {
class IOFetch : public coroutine {
public:
/// \brief Protocol to use on the fetch
enum Protocol {
UDP = 0,
TCP = 1
};
/// \brief Origin of Asynchronous I/O Call
///
/// Indicates what initiated an asynchronous I/O call and used in deciding
......@@ -149,7 +155,7 @@ public:
///
/// Just fills in the data members of the IOFetchData structure
///
/// \param proto either IPPROTO_UDP or IPPROTO_TCP
/// \param proto Protocol: either IOFetch::TCP or IOFetch::UDP
/// \param service I/O Service object to handle the asynchronous
/// operations.
/// \param query DNS question to send to the upstream server.
......@@ -163,18 +169,18 @@ public:
/// \param wait Timeout for the fetch (in ms).
///
/// TODO: May need to alter constructor (see comment 4 in Trac ticket #554)
IOFetchData(int proto, IOService& service,
IOFetchData(Protocol proto, IOService& service,
const isc::dns::Question& query, const IOAddress& address,
uint16_t port, isc::dns::OutputBufferPtr& buff, Callback* cb,
int wait)
:
socket((proto == IPPROTO_UDP) ?
socket((proto == UDP) ?
static_cast<IOAsioSocket<IOFetch>*>(
new UDPSocket<IOFetch>(service)) :
static_cast<IOAsioSocket<IOFetch>*>(
new TCPSocket<IOFetch>(service))
),
remote((proto == IPPROTO_UDP) ?
remote((proto == UDP) ?
static_cast<IOEndpoint*>(new UDPEndpoint(address, port)) :
static_cast<IOEndpoint*>(new TCPEndpoint(address, port))
),
......@@ -197,7 +203,7 @@ public:
///
/// TODO: Need to randomise the source port
///
/// \param protocol Fetch protocol, either IPPROTO_UDP or IPPROTO_TCP
/// \param protocol Fetch protocol, either IOFetch::TCP or IOFetch::UDP
/// \param service I/O Service object to handle the asynchronous
/// operations.
/// \param question DNS question to send to the upstream server.
......@@ -211,7 +217,7 @@ public:
/// (default = 53)
/// \param wait Timeout for the fetch (in ms). The default value of
/// -1 indicates no timeout.
IOFetch(int protocol, IOService& service,
IOFetch(Protocol protocol, IOService& service,
const isc::dns::Question& question, const IOAddress& address,
uint16_t port, isc::dns::OutputBufferPtr& buff, Callback* cb,
int wait = -1);
......
......@@ -98,7 +98,3 @@ private:
} // asiolink
#endif // __IO_MESSAGE_H
\ No newline at end of file
// Local Variables:
// mode: c++
// End:
......@@ -163,7 +163,7 @@ private:
int serverIndex = rand() % uc;
dlog("Sending upstream query (" + question_.toText() +
") to " + upstream_->at(serverIndex).first);
IOFetch query(IPPROTO_UDP, io_, question_,
IOFetch query(IOFetch::UDP, io_, question_,
upstream_->at(serverIndex).first,
upstream_->at(serverIndex).second, buffer_, this,
query_timeout_);
......@@ -173,7 +173,7 @@ private:
int serverIndex = rand() % zs;
dlog("Sending query to zone server (" + question_.toText() +
") to " + zone_servers_.at(serverIndex).first);
IOFetch query(IPPROTO_IDP, io_, question_,
IOFetch query(IOFetch::UDP, io_, question_,
zone_servers_.at(serverIndex).first,
zone_servers_.at(serverIndex).second, buffer_, this,
query_timeout_);
......
......@@ -33,11 +33,12 @@ run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDADD = $(GTEST_LDADD)
run_unittests_LDADD += $(SQLITE_LIBS)
run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
run_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
run_unittests_LDADD += $(top_builddir)/src/lib/resolve/libresolve.la
run_unittests_LDADD += $(top_builddir)/src/lib/cache/libcache.la
run_unittests_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) $(LOG4CXX_LDFLAGS)
......
......@@ -66,7 +66,7 @@ public:
run_(false),
question_(Name("example.net"), RRClass::IN(), RRType::A()),
buff_(new OutputBuffer(512)),
udp_fetch_(IPPROTO_UDP, service_, question_, IOAddress(TEST_HOST),
udp_fetch_(IOFetch::UDP, service_, question_, IOAddress(TEST_HOST),
TEST_PORT, buff_, this, 100)
// tcp_fetch_(service_, question_, IOAddress(TEST_HOST), TEST_PORT,
// buff_, this, 100, IPPROTO_UDP)
......
......@@ -28,7 +28,6 @@
#include <config.h>
#include <asiolink/io_asio_socket.h>
#include <asiolink/io_endpoint.h>
#include <asiolink/io_service.h>
......@@ -201,12 +200,23 @@ UDPSocket<C>::open(const IOEndpoint* endpoint, C&) {
isopen_ = true;
// Ensure it can send and receive 4K buffers.
socket_.set_option(asio::socket_base::send_buffer_size(MAX_SIZE));
socket_.set_option(asio::socket_base::receive_buffer_size(MAX_SIZE));
;
// Allow reuse of an existing port/address
socket_.set_option(asio::socket_base::reuse_address(true));
asio::ip::udp::socket::send_buffer_size snd_size;
socket_.get_option(snd_size);
if (snd_size.value() < MAX_SIZE) {
snd_size = MAX_SIZE;
socket_.set_option(snd_size);
}
asio::ip::udp::socket::receive_buffer_size rcv_size;
socket_.get_option(rcv_size);
if (rcv_size.value() < MAX_SIZE) {
rcv_size = MAX_SIZE;
socket_.set_option(rcv_size);
}
}
// Nothing was done asynchronously, so tell the caller that.
return (false);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment