Browse Source

Move send_fd and recv_fd to isc::util::io

* They are not xfr specific and can be used by more parts of the system.
* TODO: They are missing tests.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3175 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
88d4219ba9

+ 2 - 2
src/bin/xfrout/tests/Makefile.am

@@ -5,7 +5,7 @@ EXTRA_DIST = $(PYTESTS)
 # required by loadable python modules.
 # required by loadable python modules.
 LIBRARY_PATH_PLACEHOLDER =
 LIBRARY_PATH_PLACEHOLDER =
 if SET_ENV_LIBRARY_PATH
 if SET_ENV_LIBRARY_PATH
-LIBRARY_PATH_PLACEHOLDER += $(ENV_LIBRARY_PATH)=$(abs_top_builddir)/src/lib/dns/.libs:$(abs_top_builddir)/src/lib/exceptions/.libs:$(abs_top_builddir)/src/lib/xfr/.libs:$$$(ENV_LIBRARY_PATH)
+LIBRARY_PATH_PLACEHOLDER += $(ENV_LIBRARY_PATH)=$(abs_top_builddir)/src/lib/dns/.libs:$(abs_top_builddir)/src/lib/exceptions/.libs:$(abs_top_builddir)/src/lib/util/io/.libs:$$$(ENV_LIBRARY_PATH)
 endif
 endif
 
 
 # later will have configure option to choose this, like: coverage run --branch
 # later will have configure option to choose this, like: coverage run --branch
@@ -14,7 +14,7 @@ PYCOVERAGE = $(PYTHON)
 check-local:
 check-local:
 	for pytest in $(PYTESTS) ; do \
 	for pytest in $(PYTESTS) ; do \
 	echo Running test: $$pytest ; \
 	echo Running test: $$pytest ; \
-	env PYTHONPATH=$(abs_top_builddir)/src/bin/xfrout:$(abs_top_srcdir)/src/lib/python:$(abs_top_builddir)/src/lib/python:$(abs_top_builddir)/src/lib/dns/python/.libs:$(abs_top_builddir)/src/lib/xfr/.libs \
+	env PYTHONPATH=$(abs_top_builddir)/src/bin/xfrout:$(abs_top_srcdir)/src/lib/python:$(abs_top_builddir)/src/lib/python:$(abs_top_builddir)/src/lib/dns/python/.libs:$(abs_top_builddir)/src/lib/util/io/.libs \
 	$(LIBRARY_PATH_PLACEHOLDER) \
 	$(LIBRARY_PATH_PLACEHOLDER) \
 	$(PYCOVERAGE) $(abs_srcdir)/$$pytest || exit ; \
 	$(PYCOVERAGE) $(abs_srcdir)/$$pytest || exit ; \
 	done
 	done

+ 2 - 2
src/bin/xfrout/xfrout.py.in

@@ -35,12 +35,12 @@ import select
 import errno
 import errno
 from optparse import OptionParser, OptionValueError
 from optparse import OptionParser, OptionValueError
 try:
 try:
-    from libxfr_python import *
+    from libutil_io_python import *
     from pydnspp import *
     from pydnspp import *
 except ImportError as e:
 except ImportError as e:
     # C++ loadable module may not be installed; even so the xfrout process
     # C++ loadable module may not be installed; even so the xfrout process
     # must keep running, so we warn about it and move forward.
     # must keep running, so we warn about it and move forward.
-    sys.stderr.write('[b10-xfrout] failed to import DNS or XFR module: %s\n' % str(e))
+    sys.stderr.write('[b10-xfrout] failed to import DNS or isc.util.io module: %s\n' % str(e))
 
 
 isc.utils.process.rename()
 isc.utils.process.rename()
 
 

+ 1 - 1
src/lib/Makefile.am

@@ -1 +1 @@
-SUBDIRS = exceptions dns cc config datasrc python xfr bench util
+SUBDIRS = exceptions dns cc config datasrc bench util xfr python

+ 11 - 1
src/lib/util/io/Makefile.am

@@ -1,6 +1,16 @@
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 
 
 lib_LTLIBRARIES = libutil_io.la
 lib_LTLIBRARIES = libutil_io.la
-libutil_io_la_SOURCES = fd.h fd.cc
+libutil_io_la_SOURCES = fd.h fd.cc fd_share.h fd_share.cc
+libutil_io_la_CXXFLAGS = $(AM_CXXFLAGS) -fno-strict-aliasing
 
 
 CLEANFILES = *.gcno *.gcda
 CLEANFILES = *.gcno *.gcda
+
+pyexec_LTLIBRARIES = libutil_io_python.la
+# Python prefers .so, while some OSes (specifically MacOS) use a different
+# suffix for dynamic objects.  -module is necessary to work this around.
+libutil_io_python_la_LDFLAGS = -module
+libutil_io_python_la_SOURCES = fdshare_python.cc
+libutil_io_python_la_LIBADD = libutil_io.la
+libutil_io_python_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES)
+libutil_io_python_la_CXXFLAGS = $(AM_CXXFLAGS)

+ 5 - 3
src/lib/xfr/fd_share.cc

@@ -21,10 +21,11 @@
 #include <sys/socket.h>
 #include <sys/socket.h>
 #include <sys/uio.h>
 #include <sys/uio.h>
 #include <stdlib.h>             // for malloc and free
 #include <stdlib.h>             // for malloc and free
-#include <xfr/fd_share.h>
+#include "fd_share.h"
 
 
 namespace isc {
 namespace isc {
-namespace xfr {
+namespace util {
+namespace io {
 
 
 namespace {
 namespace {
 // Not all OSes support advanced CMSG macros: CMSG_LEN and CMSG_SPACE.
 // Not all OSes support advanced CMSG macros: CMSG_LEN and CMSG_SPACE.
@@ -135,5 +136,6 @@ send_fd(const int sock, const int fd) {
     return (ret >= 0 ? 0 : -1);
     return (ret >= 0 ? 0 : -1);
 }
 }
 
 
-} // End for namespace xfr
+} // End for namespace io
+} // End for namespace util
 } // End for namespace isc
 } // End for namespace isc

+ 4 - 2
src/lib/xfr/fd_share.h

@@ -18,7 +18,8 @@
 #define FD_SHARE_H_
 #define FD_SHARE_H_
 
 
 namespace isc {
 namespace isc {
-namespace xfr {
+namespace util {
+namespace io {
 
 
 // Receive socket descriptor on unix domain socket 'sock'.
 // Receive socket descriptor on unix domain socket 'sock'.
 // Returned value is the socket descriptor received.
 // Returned value is the socket descriptor received.
@@ -30,7 +31,8 @@ int recv_fd(const int sock);
 // Errors are indicated by a return value of -1.
 // Errors are indicated by a return value of -1.
 int send_fd(const int sock, const int fd);
 int send_fd(const int sock, const int fd);
 
 
-} // End for namespace xfr
+} // End for namespace io
+} // End for namespace util
 } // End for namespace isc
 } // End for namespace isc
 
 
 #endif
 #endif

+ 4 - 4
src/lib/xfr/fdshare_python.cc

@@ -20,7 +20,7 @@
 
 
 #include <config.h>
 #include <config.h>
 
 
-#include <xfr/fd_share.h>
+#include "fd_share.h"
 
 
 static PyObject*
 static PyObject*
 fdshare_recv_fd(PyObject *self UNUSED_PARAM, PyObject *args) {
 fdshare_recv_fd(PyObject *self UNUSED_PARAM, PyObject *args) {
@@ -28,7 +28,7 @@ fdshare_recv_fd(PyObject *self UNUSED_PARAM, PyObject *args) {
     if (!PyArg_ParseTuple(args, "i", &sock)) {
     if (!PyArg_ParseTuple(args, "i", &sock)) {
         return (NULL);
         return (NULL);
     }
     }
-    fd = isc::xfr::recv_fd(sock);
+    fd = isc::util::io::recv_fd(sock);
     return (Py_BuildValue("i", fd));
     return (Py_BuildValue("i", fd));
 }
 }
 
 
@@ -38,7 +38,7 @@ fdshare_send_fd(PyObject *self UNUSED_PARAM, PyObject *args) {
     if (!PyArg_ParseTuple(args, "ii", &sock, &fd)) {
     if (!PyArg_ParseTuple(args, "ii", &sock, &fd)) {
         return (NULL);
         return (NULL);
     }
     }
-    result = isc::xfr::send_fd(sock, fd);
+    result = isc::util::io::send_fd(sock, fd);
     return (Py_BuildValue("i", result));
     return (Py_BuildValue("i", result));
 }
 }
 
 
@@ -62,7 +62,7 @@ static PyModuleDef bind10_fdshare_python = {
 };
 };
 
 
 PyMODINIT_FUNC
 PyMODINIT_FUNC
-PyInit_libxfr_python(void) {
+PyInit_libutil_io_python(void) {
     PyObject *mod = PyModule_Create(&bind10_fdshare_python);
     PyObject *mod = PyModule_Create(&bind10_fdshare_python);
     if (mod == NULL) {
     if (mod == NULL) {
         return (NULL);
         return (NULL);

+ 3 - 11
src/lib/xfr/Makefile.am

@@ -1,19 +1,11 @@
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 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)/src/lib/dns -I$(top_builddir)/src/lib/dns
 
 
-AM_CXXFLAGS = $(B10_CXXFLAGS) -Wno-strict-aliasing
+AM_CXXFLAGS = $(B10_CXXFLAGS)
 AM_CXXFLAGS += -Wno-unused-parameter # see src/lib/cc/Makefile.am
 AM_CXXFLAGS += -Wno-unused-parameter # see src/lib/cc/Makefile.am
 
 
 CLEANFILES = *.gcno *.gcda
 CLEANFILES = *.gcno *.gcda
 
 
 lib_LTLIBRARIES = libxfr.la
 lib_LTLIBRARIES = libxfr.la
-libxfr_la_SOURCES = xfrout_client.h xfrout_client.cc 
-libxfr_la_SOURCES += fd_share.h fd_share.cc
-
-pyexec_LTLIBRARIES = libxfr_python.la
-# Python prefers .so, while some OSes (specifically MacOS) use a different
-# suffix for dynamic objects.  -module is necessary to work this around.
-libxfr_python_la_LDFLAGS = -module
-libxfr_python_la_SOURCES = fdshare_python.cc fd_share.cc fd_share.h
-libxfr_python_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES)
-libxfr_python_la_CXXFLAGS = $(AM_CXXFLAGS)
+libxfr_la_SOURCES = xfrout_client.h xfrout_client.cc
+libxfr_la_LIBADD = $(top_builddir)/src/lib/util/io/libutil_io.la

+ 0 - 35
src/lib/xfr/python_xfr.cc

@@ -1,35 +0,0 @@
-// Copyright (C) 2010  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.
-
-// $Id$
-
-#include <boost/python.hpp>
-#include <boost/python/class.hpp>
-#include <boost/python/module.hpp>
-#include <boost/python/def.hpp>
-#include <boost/python/exception_translator.hpp>
-#include <boost/python/return_internal_reference.hpp>
-#include <boost/python/copy_const_reference.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <xfr/fd_share.h>
-
-using namespace isc::xfr;
-using namespace boost::python;
-
-BOOST_PYTHON_MODULE(bind10_xfr)
-{
-    def("recv_fd", &recv_fd);
-    def("send_fd", &send_fd);
-}

+ 2 - 1
src/lib/xfr/xfrout_client.cc

@@ -22,10 +22,11 @@
 #include <unistd.h>
 #include <unistd.h>
 #include <asio.hpp>
 #include <asio.hpp>
 
 
-#include <xfr/fd_share.h>
+#include <util/io/fd_share.h>
 #include <xfr/xfrout_client.h>
 #include <xfr/xfrout_client.h>
 
 
 using namespace std;
 using namespace std;
+using namespace isc::util::io;
 using asio::local::stream_protocol;
 using asio::local::stream_protocol;
 
 
 namespace isc {
 namespace isc {