Commit a151c4a6 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[trac569] split up udpdns.[h|cc] and tcpdns.[h|cc] too

and moved them out of internal. Changed the internal/ workaround (to prevent files outside of asiolink/ to indirectly include asio.hpp), the .cc files that include the relevant headers must include asio.hpp themselves (and this is checked in the headers)
Also moved coroutine out of internal.
Tests are still todo (which is why internal/ still exists)
parent c9eb48c9
......@@ -25,9 +25,12 @@ libasiolink_la_SOURCES += iosocket.cc iosocket.h
libasiolink_la_SOURCES += iomessage.h
libasiolink_la_SOURCES += ioaddress.cc ioaddress.h
libasiolink_la_SOURCES += ioendpoint.cc ioendpoint.h
libasiolink_la_SOURCES += udpdns.cc internal/udpdns.h
libasiolink_la_SOURCES += tcpdns.cc internal/tcpdns.h
libasiolink_la_SOURCES += internal/coroutine.h
libasiolink_la_SOURCES += udp_endpoint.h udp_socket.h
libasiolink_la_SOURCES += udp_server.h udp_server.cc
libasiolink_la_SOURCES += udp_query.h udp_query.cc
libasiolink_la_SOURCES += tcp_endpoint.h tcp_socket.h
libasiolink_la_SOURCES += tcp_server.h tcp_server.cc
libasiolink_la_SOURCES += coroutine.h
# Note: the ordering matters: -Wno-... must follow -Wextra (defined in
# B10_CXXFLAGS)
libasiolink_la_CXXFLAGS = $(AM_CXXFLAGS)
......
......@@ -18,6 +18,7 @@
#include <asiolink/iomessage.h>
#include <asiolink/dns_server.h>
#include <dns/buffer.h>
#include <dns/message.h>
namespace asiolink {
......
......@@ -18,8 +18,9 @@
#include <asio/ip/address.hpp>
#include <asiolink/internal/tcpdns.h>
#include <asiolink/internal/udpdns.h>
#include <asio.hpp>
#include <tcp_server.h>
#include <asiolink/udp_server.h>
#include <log/dummylog.h>
......
......@@ -19,7 +19,7 @@
#include <dns/question.h>
#include <asiolink/internal/udpdns.h>
#include <asiolink/udp_query.h>
using namespace asio;
using namespace isc::dns;
......
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
// 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
......@@ -18,9 +18,11 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <asio.hpp>
#include <asiolink/asiolink.h>
#include <internal/tcpdns.h>
#include <internal/udpdns.h>
#include <asiolink/tcp_endpoint.h>
#include <asiolink/udp_endpoint.h>
using namespace std;
......
......@@ -16,10 +16,11 @@
#include <asio/ip/address.hpp>
#include <asio.hpp>
#include <asiolink/recursive_query.h>
#include <asiolink/dns_service.h>
#include <asiolink/internal/tcpdns.h>
#include <asiolink/internal/udpdns.h>
#include <asiolink/udp_query.h>
#include <log/dummylog.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.
#ifndef __TCP_ENDPOINT_H
#define __TCP_ENDPOINT_H 1
#ifndef ASIO_HPP
#error "asio.hpp must be included before including this, see asiolink.h as to why"
#endif
#include <asiolink/ioendpoint.h>
namespace asiolink {
/// \brief The \c TCPEndpoint class is a concrete derived class of
/// \c IOEndpoint that represents an endpoint of a TCP connection.
///
/// In the current implementation, an object of this class is always
/// instantiated within the wrapper routines. Applications are expected to
/// get access to the object via the abstract base class, \c IOEndpoint.
/// This design may be changed when we generalize the wrapper interface.
///
/// Note: this implementation is optimized for the case where this object
/// is created from an ASIO endpoint object in a receiving code path
/// by avoiding to make a copy of the base endpoint. For TCP it may not be
/// a big deal, but when we receive UDP packets at a high rate, the copy
/// overhead might be significant.
class TCPEndpoint : public IOEndpoint {
public:
///
/// \name Constructors and Destructor
///
//@{
/// \brief Constructor from a pair of address and port.
///
/// \param address The IP address of the endpoint.
/// \param port The TCP port number of the endpoint.
TCPEndpoint(const IOAddress& address, const unsigned short port) :
asio_endpoint_placeholder_(
new asio::ip::tcp::endpoint(
asio::ip::address::from_string(address.toText()), port)),
asio_endpoint_(*asio_endpoint_placeholder_)
{}
/// \brief Constructor from an ASIO TCP endpoint.
///
/// This constructor is designed to be an efficient wrapper for the
/// corresponding ASIO class, \c tcp::endpoint.
///
/// \param asio_endpoint The ASIO representation of the TCP endpoint.
TCPEndpoint(const asio::ip::tcp::endpoint& asio_endpoint) :
asio_endpoint_placeholder_(NULL), asio_endpoint_(asio_endpoint)
{}
/// \brief The destructor.
~TCPEndpoint() { delete asio_endpoint_placeholder_; }
//@}
IOAddress getAddress() const {
return (asio_endpoint_.address());
}
uint16_t getPort() const {
return (asio_endpoint_.port());
}
short getProtocol() const {
return (asio_endpoint_.protocol().protocol());
}
short getFamily() const {
return (asio_endpoint_.protocol().family());
}
// This is not part of the exosed IOEndpoint API but allows
// direct access to the ASIO implementation of the endpoint
const asio::ip::tcp::endpoint& getASIOEndpoint() const {
return (asio_endpoint_);
}
private:
const asio::ip::tcp::endpoint* asio_endpoint_placeholder_;
const asio::ip::tcp::endpoint& asio_endpoint_;
};
} // namespace asiolink
#endif // __TCP_ENDPOINT_H
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
// 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
......@@ -14,22 +14,17 @@
#include <config.h>
#include <unistd.h> // for some IPC/network system calls
#include <sys/socket.h>
#include <netinet/in.h>
#include <boost/shared_array.hpp>
#include <asio.hpp>
#include <asio/ip/address.hpp>
#include <boost/array.hpp>
#include <boost/shared_ptr.hpp>
#include <log/dummylog.h>
#include <dns/buffer.h>
#include <dns/message.h>
#include <asiolink/tcp_endpoint.h>
#include <asiolink/tcp_socket.h>
#include <asiolink/tcp_server.h>
#include <asiolink.h>
#include <internal/coroutine.h>
#include <internal/tcpdns.h>
using namespace asio;
using asio::ip::udp;
......@@ -39,7 +34,8 @@ using namespace std;
using namespace isc::dns;
namespace asiolink {
/// The following functions implement the \c UDPServer class.
/// The following functions implement the \c TCPServer class.
///
/// The constructor
TCPServer::TCPServer(io_service& io_service,
......@@ -191,4 +187,5 @@ TCPServer::resume(const bool done) {
io_.post(*this);
}
}
} // namespace asiolink
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
// 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
......@@ -12,121 +12,21 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef __TCPDNS_H
#define __TCPDNS_H 1
#ifndef __TCP_SERVER_H
#define __TCP_SERVER_H 1
#include <config.h>
#ifndef ASIO_HPP
#error "asio.hpp must be included before including this, see asiolink.h as to why"
#endif
#include <asio.hpp>
#include <boost/shared_array.hpp>
#include <boost/shared_ptr.hpp>
#include <dns/buffer.h>
#include <dns/message.h>
#include <asiolink/asiolink.h>
#include <asiolink/internal/coroutine.h>
#include <asiolink/coroutine.h>
// This file contains TCP-specific implementations of generic classes
// defined in asiolink.h. It is *not* intended to be part of the public
// API.
namespace asiolink {
/// \brief The \c TCPEndpoint class is a concrete derived class of
/// \c IOEndpoint that represents an endpoint of a TCP connection.
///
/// In the current implementation, an object of this class is always
/// instantiated within the wrapper routines. Applications are expected to
/// get access to the object via the abstract base class, \c IOEndpoint.
/// This design may be changed when we generalize the wrapper interface.
///
/// Note: this implementation is optimized for the case where this object
/// is created from an ASIO endpoint object in a receiving code path
/// by avoiding to make a copy of the base endpoint. For TCP it may not be
/// a big deal, but when we receive UDP packets at a high rate, the copy
/// overhead might be significant.
class TCPEndpoint : public IOEndpoint {
public:
///
/// \name Constructors and Destructor
///
//@{
/// \brief Constructor from a pair of address and port.
///
/// \param address The IP address of the endpoint.
/// \param port The TCP port number of the endpoint.
TCPEndpoint(const IOAddress& address, const unsigned short port) :
asio_endpoint_placeholder_(
new asio::ip::tcp::endpoint(
asio::ip::address::from_string(address.toText()), port)),
asio_endpoint_(*asio_endpoint_placeholder_)
{}
/// \brief Constructor from an ASIO TCP endpoint.
///
/// This constructor is designed to be an efficient wrapper for the
/// corresponding ASIO class, \c tcp::endpoint.
///
/// \param asio_endpoint The ASIO representation of the TCP endpoint.
TCPEndpoint(const asio::ip::tcp::endpoint& asio_endpoint) :
asio_endpoint_placeholder_(NULL), asio_endpoint_(asio_endpoint)
{}
/// \brief The destructor.
~TCPEndpoint() { delete asio_endpoint_placeholder_; }
//@}
IOAddress getAddress() const {
return (asio_endpoint_.address());
}
uint16_t getPort() const {
return (asio_endpoint_.port());
}
short getProtocol() const {
return (asio_endpoint_.protocol().protocol());
}
short getFamily() const {
return (asio_endpoint_.protocol().family());
}
// This is not part of the exosed IOEndpoint API but allows
// direct access to the ASIO implementation of the endpoint
const asio::ip::tcp::endpoint& getASIOEndpoint() const {
return (asio_endpoint_);
}
private:
const asio::ip::tcp::endpoint* asio_endpoint_placeholder_;
const asio::ip::tcp::endpoint& asio_endpoint_;
};
/// \brief The \c TCPSocket class is a concrete derived class of
/// \c IOSocket that represents a TCP socket.
///
/// In the current implementation, an object of this class is always
/// instantiated within the wrapper routines. Applications are expected to
/// get access to the object via the abstract base class, \c IOSocket.
/// This design may be changed when we generalize the wrapper interface.
class TCPSocket : public IOSocket {
private:
TCPSocket(const TCPSocket& source);
TCPSocket& operator=(const TCPSocket& source);
public:
/// \brief Constructor from an ASIO TCP socket.
///
/// \param socket The ASIO representation of the TCP socket.
TCPSocket(asio::ip::tcp::socket& socket) : socket_(socket) {}
int getNative() const { return (socket_.native()); }
int getProtocol() const { return (IPPROTO_TCP); }
private:
asio::ip::tcp::socket& socket_;
};
/// \brief A TCP-specific \c DNSServer object.
///
......@@ -215,10 +115,5 @@ private:
boost::shared_ptr<IOSocket> iosock_;
};
}
#endif // __TCPDNS_H
// Local Variables:
// mode: c++
// End:
} // namespace asiolink
#endif // __TCP_SERVER_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.
#ifndef __TCP_SOCKET_H
#define __TCP_SOCKET_H 1
#ifndef ASIO_HPP
#error "asio.hpp must be included before including this, see asiolink.h as to why"
#endif
#include <asiolink/iosocket.h>
namespace asiolink {
/// \brief The \c TCPSocket class is a concrete derived class of
/// \c IOSocket that represents a TCP socket.
///
/// In the current implementation, an object of this class is always
/// instantiated within the wrapper routines. Applications are expected to
/// get access to the object via the abstract base class, \c IOSocket.
/// This design may be changed when we generalize the wrapper interface.
class TCPSocket : public IOSocket {
private:
TCPSocket(const TCPSocket& source);
TCPSocket& operator=(const TCPSocket& source);
public:
/// \brief Constructor from an ASIO TCP socket.
///
/// \param socket The ASIO representation of the TCP socket.
TCPSocket(asio::ip::tcp::socket& socket) : socket_(socket) {}
int getNative() const { return (socket_.native()); }
int getProtocol() const { return (IPPROTO_TCP); }
private:
asio::ip::tcp::socket& socket_;
};
} // namespace asiolink
#endif // __TCP_SOCKET_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.
#ifndef __UDP_ENDPOINT_H
#define __UDP_ENDPOINT_H 1
#ifndef ASIO_HPP
#error "asio.hpp must be included before including this, see asiolink.h as to why"
#endif
#include <asiolink/ioendpoint.h>
namespace asiolink {
/// \brief The \c UDPEndpoint class is a concrete derived class of
/// \c IOEndpoint that represents an endpoint of a UDP packet.
///
/// Other notes about \c TCPEndpoint applies to this class, too.
class UDPEndpoint : public IOEndpoint {
public:
///
/// \name Constructors and Destructor.
///
//@{
/// \brief Constructor from a pair of address and port.
///
/// \param address The IP address of the endpoint.
/// \param port The UDP port number of the endpoint.
UDPEndpoint(const IOAddress& address, const unsigned short port) :
asio_endpoint_placeholder_(
new asio::ip::udp::endpoint(asio::ip::address::from_string(address.toText()),
port)),
asio_endpoint_(*asio_endpoint_placeholder_)
{}
/// \brief Constructor from an ASIO UDP endpoint.
///
/// This constructor is designed to be an efficient wrapper for the
/// corresponding ASIO class, \c udp::endpoint.
///
/// \param asio_endpoint The ASIO representation of the UDP endpoint.
UDPEndpoint(const asio::ip::udp::endpoint& asio_endpoint) :
asio_endpoint_placeholder_(NULL), asio_endpoint_(asio_endpoint)
{}
/// \brief The destructor.
~UDPEndpoint() { delete asio_endpoint_placeholder_; }
//@}
inline IOAddress getAddress() const {
return (asio_endpoint_.address());
}
inline uint16_t getPort() const {
return (asio_endpoint_.port());
}
inline short getProtocol() const {
return (asio_endpoint_.protocol().protocol());
}
inline short getFamily() const {
return (asio_endpoint_.protocol().family());
}
// This is not part of the exosed IOEndpoint API but allows
// direct access to the ASIO implementation of the endpoint
inline const asio::ip::udp::endpoint& getASIOEndpoint() const {
return (asio_endpoint_);
}
private:
const asio::ip::udp::endpoint* asio_endpoint_placeholder_;
const asio::ip::udp::endpoint& asio_endpoint_;
};
} // namespace asiolink
#endif // __UDP_ENDPOINT_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.
#ifndef __UDP_QUERY_H
#define __UDP_QUERY_H 1
#ifndef ASIO_HPP
#error "asio.hpp must be included before including this, see asiolink.h as to why"
#endif
#include <dns/buffer.h>
#include <asiolink/ioaddress.h>
#include <asiolink/coroutine.h>
namespace asiolink {
//
// Asynchronous UDP coroutine for upstream queries
//
class UDPQuery : public coroutine {
public:
// TODO Maybe this should be more generic than just for UDPQuery?
///
/// \brief Result of the query
///
/// This is related only to contacting the remote server. If the answer
///indicates error, it is still counted as SUCCESS here, if it comes back.
///
enum Result {
SUCCESS,
TIME_OUT,
STOPPED
};
/// Abstract callback for the UDPQuery.
class Callback {
public:
virtual ~Callback() {}
/// This will be called when the UDPQuery is completed
virtual void operator()(Result result) = 0;
};
///
/// \brief Constructor.
///
/// It creates the query.
/// @param callback will be called when we terminate. It is your task to
/// delete it if allocated on heap.
///@param timeout in ms.
///
explicit UDPQuery(asio::io_service& io_service,
const isc::dns::Question& q,
const IOAddress& addr, uint16_t port,
isc::dns::OutputBufferPtr buffer,
Callback* callback, int timeout = -1);
void operator()(asio::error_code ec = asio::error_code(),
size_t length = 0);
/// Terminate the query.
void stop(Result reason = STOPPED);
private:
enum { MAX_LENGTH = 4096 };
///
/// \short Private data
///
/// They are not private because of stability of the
/// interface (this is private class anyway), but because this class
/// will be copyed often (it is used as a coroutine and passed as callback
/// to many async_*() functions) and we want keep the same data. Some of
/// the data is not copyable too.
///
struct PrivateData;
boost::shared_ptr<PrivateData> data_;
};
} // namespace asiolink
#endif // __UDP_QUERY_H
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
// 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
......@@ -12,109 +12,21 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef __UDPDNS_H
#define __UDPDNS_H 1
#ifndef __UDP_SERVER_H
#define __UDP_SERVER_H 1
#include <config.h>