Commit 737c49cf authored by JINMEI Tatuya's avatar JINMEI Tatuya

addressed some portability issues with non boost ASIO:

 - suppress the gcc unused parameters warning selectively (as a workaround) in a most portable way
 - introduce B10_CXXFLAGS as the default to AM_CXXFLAGS to make the first change possible (that's why I modified so many other Makefile.am's even if they are irrelevant to asio)
 - remove dependency on boost system library: it was only needed for the boost version of ASIO.
 - hide details that require ASIO related definitions from xfr_client.h to avoid being hit by the 'unused parameter' problem accidentally.


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac168@1953 e5f2f494-b856-4b98-b285-d166d9295462
parent 748e5c85
......@@ -87,9 +87,21 @@ AC_SUBST(PYTHON_LIB)
# TODO: check for _sqlite3.py module
# default compiler warning settings
#
# B10_CXXFLAGS is the default C++ compiler flags. This will (and should) be
# used as the default value for each specifc AM_CXXFLAGS:
# AM_CXXFLAGS = $(B10_CXXFLAGS)
# AM_CXXFLAGS += ... # add module specific flags
# We need this so that we can disable some specific compiler warnings per
# module basis; since AM_CXXFLAGS are placed before CXXFLAGS, and since
# gcc's -Wno-XXX option must be specified after -Wall or -Wextra, we cannot
# specify the default warning flags in CXXFLAGS and let specific modules
# "override" the default.
#
B10_CXXFLAGS=
if test "X$GCC" = "Xyes"; then
CXXFLAGS="$CXXFLAGS -g -Wall -Wextra -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare"
B10_CXXFLAGS="-g -Wall -Wextra -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare"
UNUSED_PARAM_ATTRIBUTE='__attribute__((unused))'
# Certain versions of gcc (g++) have a bug that incorrectly warns about
......@@ -97,23 +109,27 @@ UNUSED_PARAM_ATTRIBUTE='__attribute__((unused))'
# translation unit. For these versions we have to disable -Werror.
werror_ok=0
CXXFLAGS_SAVED="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -Werror"
CXXFLAGS="$CXXFLAGS $B10_CXXFLAGS -Werror"
AC_MSG_CHECKING(for in-TU anonymous namespace breakage)
AC_TRY_COMPILE([namespace { class Foo {}; }
namespace isc {class Bar {Foo foo_;};} ],,
[AC_MSG_RESULT(no)
werror_ok=1],
werror_ok=1
B10_CXXFLAGS="$B10_CXXFLAGS -Werror"],
[AC_MSG_RESULT(yes)])
CXXFLAGS="$CXXFLAGS_SAVED"
fi
AC_DEFINE_UNQUOTED(UNUSED_PARAM, $UNUSED_PARAM_ATTRIBUTE, Define to compiler keyword indicating a function argument is intentionally unused)
fi dnl GCC = yes
AM_CONDITIONAL(GCC_WERROR_OK, test $werror_ok = 1)
AC_DEFINE_UNQUOTED(UNUSED_PARAM, $UNUSED_PARAM_ATTRIBUTE, Define to compiler keyword indicating a function argument is intentionally unused)
# produce PIC unless we disable shared libraries. need this for python bindings.
if test $enable_shared != "no" -a "X$GCC" = "Xyes"; then
CXXFLAGS="$CXXFLAGS -fPIC"
B10_CXXFLAGS="$B10_CXXFLAGS -fPIC"
fi
AC_SUBST(B10_CXXFLAGS)
# Checks for libraries.
AC_SEARCH_LIBS(inet_pton, [nsl])
......@@ -193,52 +209,6 @@ AC_HELP_STRING([--with-boost-lib=PATH],
fi])
AC_SUBST(BOOST_LDFLAGS)
# Check availability of the Boost System library
AC_MSG_CHECKING([for boost::system library])
AC_ARG_WITH([boost-system],
AC_HELP_STRING([--with-boost-system],
[specify whether to use the boost system library]),
[with_boost_system="$withval"], [with_boost_system="auto"])
if test "$with_boost_system" != "no"; then
LDFLAGS_SAVED="$LDFLAGS"
LIBS_SAVED="$LIBS"
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -Iext/boost"
for BOOST_TRY_LIB in boost_system boost_system-mt; do
LDFLAGS="$LDFLAGS_SAVED ${BOOST_LDFLAGS}"
LIBS="$LIBS_SAVED -l${BOOST_TRY_LIB}"
AC_TRY_LINK([#include <boost/system/error_code.hpp>],
[ boost::system::error_code error_code;
std::string message(error_code.message());
return 0; ],
[ AC_MSG_RESULT(yes)
BOOST_SYSTEM_LIB="-l${BOOST_TRY_LIB}"
],[])
if test "X${BOOST_SYSTEM_LIB}" != X; then
break
fi
done
LDFLAGS="$LDFLAGS_SAVED"
CPPFLAGS="$CPPFLAGS_SAVED"
LIBS="$LIBS_SAVED"
fi
if test "X${BOOST_SYSTEM_LIB}" = X; then
AC_MSG_RESULT(no)
if test "$with_boost_system" = "yes"; then
AC_MSG_ERROR([boost system library is requested but not found])
fi
else
AC_DEFINE(HAVE_BOOST_SYSTEM, 1, Define to 1 if boost system library is available)
fi
AM_CONDITIONAL(HAVE_BOOST_SYSTEM, test "X${BOOST_SYSTEM_LIB}" != X)
AC_SUBST(BOOST_SYSTEM_LIB)
# Check availability of the Boost Python library
AC_MSG_CHECKING([for boost::python library])
......@@ -476,9 +446,9 @@ Flags:
CPPFLAGS: $CPPFLAGS
CFLAGS: $CFLAGS
CXXFLAGS: $CXXFLAGS
B10_CXXFLAGS: $B10_CXXFLAGS
dnl includes too
Boost Python: $BOOST_PYTHON_LIB
Boost System: $BOOST_SYSTEM_LIB
SQLite: $SQLITE_CFLAGS
$SQLITE_LIBS
......
......@@ -2,9 +2,8 @@ SUBDIRS = . tests
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
if GCC_WERROR_OK
AM_CPPFLAGS += -Werror
endif
AM_CXXFLAGS = $(B10_CXXFLAGS)
pkglibexecdir = $(libexecdir)/@PACKAGE@
......@@ -34,7 +33,10 @@ spec_config.h: spec_config.h.pre
# only for which we accept the unused-parameter warning.
lib_LIBRARIES = libasio_link.a
libasio_link_a_SOURCES = asio_link.cc asio_link.h
libasio_link_a_CPPFLAGS = $(AM_CPPFLAGS) -Wno-error=unused-parameter
# Note: the ordering matters: -Wno-... must follow -Wextra (defined in
# B10_CXXFLAGS)
libasio_link_a_CXXFLAGS = $(AM_CXXFLAGS) -Wno-unused-parameter
libasio_link_a_CPPFLAGS = $(AM_CPPFLAGS)
BUILT_SOURCES = spec_config.h
pkglibexec_PROGRAMS = b10-auth
......
......@@ -14,11 +14,6 @@
// $Id$
// Suppress "unused parameter" warnings that turn up in the ASIO code
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#include <config.h>
#include <asio.hpp>
......@@ -28,15 +23,66 @@
#include <dns/message.h>
#include <dns/messagerenderer.h>
#if defined(HAVE_BOOST_PYTHON)
#define USE_XFROUT
#include <xfr/xfrout_client.h>
#endif
#include <asio_link.h>
#include "spec_config.h" // for XFROUT. should not be here.
#include "auth_srv.h"
using namespace asio;
using ip::udp;
using ip::tcp;
using namespace std;
using namespace isc::dns;
#ifdef USE_XFROUT
using namespace isc::xfr;
#endif
namespace {
// As a short term workaround, we have XFROUT specific code. We should soon
// refactor the code with some abstraction so that we can separate this level
// details from the (AS)IO module.
#ifdef USE_XFROUT
//TODO. The sample way for checking axfr query, the code should be merged to auth server class
bool
check_axfr_query(char* const msg_data, const uint16_t msg_len) {
if (msg_len < 15) {
return false;
}
const uint16_t query_type = *(uint16_t *)(msg_data + (msg_len - 4));
if ( query_type == 0xFC00) {
return true;
}
return false;
}
//TODO. Send the xfr query to xfrout module, the code should be merged to auth server class
void
dispatch_axfr_query(const int tcp_sock, char const axfr_query[],
const uint16_t query_len)
{
string path(UNIX_SOCKET_FILE);
XfroutClient xfr_client(path);
try {
xfr_client.connect();
xfr_client.sendXfroutRequestInfo(tcp_sock, (uint8_t *)axfr_query,
query_len);
xfr_client.disconnect();
}
catch (const exception & err) {
//if (verbose_mode)
cerr << "error handle xfr query:" << err.what() << endl;
}
}
#endif
}
namespace asio_link {
//
......
......@@ -39,21 +39,12 @@
#include <cc/data.h>
#include <config/ccsession.h>
#if defined(HAVE_BOOST_PYTHON)
#define USE_XFROUT
#include <xfr/xfrout_client.h>
#endif
#include "spec_config.h"
#include "common.h"
#include "auth_srv.h"
#include "asio_link.h"
using namespace std;
#ifdef USE_XFROUT
using namespace isc::xfr;
#endif
using namespace isc::data;
using namespace isc::cc;
using namespace isc::config;
......@@ -93,39 +84,6 @@ my_command_handler(const string& command, const ElementPtr args) {
return answer;
}
#ifdef USE_XFROUT
//TODO. The sample way for checking axfr query, the code should be merged to auth server class
static bool
check_axfr_query(char *msg_data, uint16_t msg_len)
{
if (msg_len < 15)
return false;
uint16_t query_type = *(uint16_t *)(msg_data + (msg_len - 4));
if ( query_type == 0xFC00)
return true;
return false;
}
//TODO. Send the xfr query to xfrout module, the code should be merged to auth server class
static void
dispatch_axfr_query(int tcp_sock, char axfr_query[], uint16_t query_len)
{
std::string path = string(UNIX_SOCKET_FILE);
XfroutClient xfr_client(path);
try {
xfr_client.connect();
xfr_client.sendXfroutRequestInfo(tcp_sock, (uint8_t *)axfr_query, query_len);
xfr_client.disconnect();
}
catch (const std::exception & err) {
//if (verbose_mode)
cerr << "error handle xfr query:" << err.what() << endl;
}
}
#endif
void
usage() {
cerr << "Usage: b10-auth [-p port] [-4|-6]" << endl;
......
......@@ -2,6 +2,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_builddir)/src/lib/dns -I$(top_srcdir)/src/bin
AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(srcdir)/testdata\"
AM_CXXFLAGS = $(B10_CXXFLAGS)
CLEANFILES = *.gcno *.gcda
TESTS =
......
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
AM_CXXFLAGS = $(B10_CXXFLAGS)
CLEANFILES = *.gcno *.gcda
bin_PROGRAMS = host
......
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CXXFLAGS = $(B10_CXXFLAGS)
# ASIO header files used in session.cc will trigger "unused-parameter"
# error. Unfortunately there doesn't seem to be an easy way to selectively
# avoid the error. As a short term workaround we suppress this warning
# for the entire this module. See also src/bin/auth/Makefile.am.
AM_CXXFLAGS += -Wno-unused-parameter
lib_LIBRARIES = libcc.a
libcc_a_SOURCES = data.cc data.h session.cc session.h
......
......@@ -14,12 +14,7 @@
// $Id$
// Suppress "unused parameter" warnings that turn up in the ASIO code
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#include "config.h"
#include <config.h>
#include <stdint.h>
......
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib -Wno-strict-aliasing
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CXXFLAGS = $(B10_CXXFLAGS) -Wno-strict-aliasing
lib_LTLIBRARIES = libcfgclient.la
libcfgclient_la_SOURCES = config_data.h config_data.cc module_spec.h module_spec.cc ccsession.cc ccsession.h
......
AM_CPPFLAGS = -I$(top_srcdir)/src/lib
AM_CXXFLAGS = $(B10_CXXFLAGS)
AM_CXXFLAGS += -Wno-unused-parameter # see src/lib/cc/Makefile.am
CLEANFILES = *.gcno *.gcda
lib_LTLIBRARIES = libfake_session.la
......
......@@ -4,6 +4,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
AM_CPPFLAGS += $(SQLITE_CFLAGS)
AM_CXXFLAGS = $(B10_CXXFLAGS)
CLEANFILES = *.gcno *.gcda
lib_LTLIBRARIES = libdatasrc.la
......
......@@ -2,6 +2,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_builddir)/src/lib/dns -I$(top_srcdir)/src/lib/dns
AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(srcdir)/testdata\"
AM_CXXFLAGS = $(B10_CXXFLAGS)
CLEANFILES = *.gcno *.gcda
TESTS =
......
SUBDIRS = . tests
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
if GCC_WERROR_OK
AM_CPPFLAGS += -Werror
endif
AM_CXXFLAGS = $(B10_CXXFLAGS)
CLEANFILES = *.gcno *.gcda
CLEANFILES += rrclass.h rrtype.h rrparamregistry.cc rdataclass.h rdataclass.cc
......@@ -86,10 +84,11 @@ if HAVE_BOOST_PYTHON
pyexec_LTLIBRARIES = bind10_dns.la
bind10_dns_la_SOURCES = python_dns.cc
bind10_dns_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES)
bind10_dns_la_CXXFLAGS = $(AM_CXXFLAGS) $(B10_CXXFLAGS)
if GCC_WERROR_OK
# XXX: Boost.Python triggers strict aliasing violation, so if we use -Werror
# we need to suppress the warnings.
bind10_dns_la_CPPFLAGS += -fno-strict-aliasing
bind10_dns_la_CXXFLAGS += -fno-strict-aliasing
endif
bind10_dns_la_LDFLAGS = $(BOOST_LDFLAGS) $(PYTHON_LDFLAGS)
# Python prefers .so, while some OSes (specifically MacOS) use a different
......
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(srcdir)/testdata\"
AM_CXXFLAGS = $(B10_CXXFLAGS)
CLEANFILES = *.gcno *.gcda
......
AM_CXXFLAGS=$(B10_CXXFLAGS)
lib_LTLIBRARIES = libexceptions.la
libexceptions_la_SOURCES = exceptions.h exceptions.cc
......
......@@ -2,11 +2,10 @@ SUBDIRS = .
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
AM_CPPFLAGS += -I$(top_srcdir)/ext -Wno-strict-aliasing
AM_CPPFLAGS += -I$(top_srcdir)/ext
if GCC_WERROR_OK
AM_CPPFLAGS += -Werror
endif
AM_CXXFLAGS = $(B10_CXXFLAGS) -Wno-strict-aliasing
AM_CXXFLAGS += -Wno-unused-parameter # see src/lib/cc/Makefile.am
CLEANFILES = *.gcno *.gcda
......@@ -18,10 +17,11 @@ if HAVE_BOOST_PYTHON
pyexec_LTLIBRARIES = bind10_xfr.la
bind10_xfr_la_SOURCES = python_xfr.cc fd_share.cc fd_share.h
bind10_xfr_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES)
bind10_xfr_la_CXXFLAGS = $(AM_CXXFLAGS)
if GCC_WERROR_OK
# XXX: Boost.Python triggers strict aliasing violation, so if we use -Werror
# we need to suppress the warnings.
bind10_xfr_la_CPPFLAGS += -fno-strict-aliasing
bind10_xfr_la_CXXFLAGS += -fno-strict-aliasing
endif
bind10_xfr_la_LDFLAGS = $(BOOST_LDFLAGS) $(PYTHON_LDFLAGS)
# Python prefers .so, while some OSes (specifically MacOS) use a different
......
......@@ -17,46 +17,72 @@
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <asio.hpp>
#include "fd_share.h"
#include "xfrout_client.h"
using namespace std;
using asio::local::stream_protocol;
namespace isc {
namespace xfr {
struct XfroutClientImpl {
XfroutClientImpl(const string& file);
const std::string file_path_;
asio::io_service io_service_;
// The socket used to communicate with the xfrout server.
stream_protocol::socket socket_;
};
XfroutClientImpl::XfroutClientImpl(const string& file) :
file_path_(file), socket_(io_service_)
{}
XfroutClient::XfroutClient(const string& file) :
impl_(new XfroutClientImpl(file))
{}
XfroutClient::~XfroutClient()
{
delete impl_;
}
void
XfroutClient::connect() {
socket_.connect(stream_protocol::endpoint(file_path_));
impl_->socket_.connect(stream_protocol::endpoint(impl_->file_path_));
}
void
XfroutClient::disconnect() {
socket_.close();
impl_->socket_.close();
}
int
XfroutClient::sendXfroutRequestInfo(const int tcp_sock, uint8_t* msg_data,
const uint16_t msg_len)
{
if (-1 == send_fd(socket_.native(), tcp_sock)) {
if (-1 == send_fd(impl_->socket_.native(), tcp_sock)) {
isc_throw(XfroutError,
"Fail to send socket descriptor to xfrout module");
}
// XXX: this shouldn't be blocking send, even though it's unlikely to block.
const uint8_t lenbuf[2] = { msg_len >> 8, msg_len & 0xff };
if (send(socket_.native(), lenbuf, sizeof(lenbuf), 0) != sizeof(lenbuf)) {
if (send(impl_->socket_.native(), lenbuf, sizeof(lenbuf), 0) !=
sizeof(lenbuf)) {
isc_throw(XfroutError,
"failed to send XFR request length to xfrout module");
}
if (send(socket_.native(), msg_data, msg_len, 0) != msg_len) {
if (send(impl_->socket_.native(), msg_data, msg_len, 0) != msg_len) {
isc_throw(XfroutError,
"failed to send XFR request data to xfrout module");
}
int databuf = 0;
if (recv(socket_.native(), &databuf, sizeof(int), 0) != 0) {
if (recv(impl_->socket_.native(), &databuf, sizeof(int), 0) != 0) {
isc_throw(XfroutError,
"xfr query hasn't been processed properly by xfrout module");
}
......
......@@ -17,36 +17,38 @@
#ifndef _XFROUT_CLIENT_H
#define _XFROUT_CLIENT_H
#include <stdint.h>
#include <string>
#include <asio.hpp>
#include <exceptions/exceptions.h>
namespace isc {
namespace xfr {
struct XfroutClientImpl;
class XfroutError: public Exception {
public:
XfroutError(const char *file, size_t line, const char *what):
isc::Exception(file, line, what) {}
};
using asio::local::stream_protocol;
class XfroutClient {
public:
XfroutClient(const std::string& file):
socket_(io_service_), file_path_(file) {}
XfroutClient(const std::string& file);
~XfroutClient();
private:
// make this class non copyable
XfroutClient(const XfroutClient& source);
XfroutClient& operator=(const XfroutClient& source);
public:
void connect();
void disconnect();
int sendXfroutRequestInfo(int tcp_sock, uint8_t* msg_data,
uint16_t msg_len);
private:
asio::io_service io_service_;
// The socket used to communicate with the xfrout server.
stream_protocol::socket socket_;
const std::string file_path_;
XfroutClientImpl* impl_;
};
} // End for namespace xfr
......
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