diff --git a/Socket/Protocols/UN/UNAddress.cc b/Socket/Protocols/UN/UNAddress.cc index 870f2b9846bb2231dd71848bea423cfdb2da76b9..70aab9a968fe7889143366c2c5a46bbc748cbf56 100644 --- a/Socket/Protocols/UN/UNAddress.cc +++ b/Socket/Protocols/UN/UNAddress.cc @@ -36,9 +36,8 @@ prefix_ senf::UNAddress::UNAddress() } prefix_ senf::UNAddress::UNAddress(boost::filesystem::path p) - //:path(p) { - + path = p; } @@ -52,12 +51,18 @@ prefix_ senf::UNAddress::UNAddress senf::UNAddress::fromPath(boost::filesystem:: } prefix_ std::string senf::UNAddress::pathString() + const { return path.string(); } +prefix_ senf::UNAddress::UNAddress senf::UNAddress::clone() +{ + senf::UNAddress::UNAddress local_addr = senf::UNAddress::UNAddress(pathString()); + return local_addr; +} -prefix_ const std::ostream & senf::operator<<(std::ostream & os, UNAddress const & addr) +prefix_ std::ostream & senf::operator<<(std::ostream & os, UNAddress const & addr) { os << addr.pathString(); return os; diff --git a/Socket/Protocols/UN/UNAddress.hh b/Socket/Protocols/UN/UNAddress.hh index 67a7061ac78bd0ee22571e3929aad4fffdaed43d..e5cb5f2a6e1f32e2f646c7d642d1189d61dfa2d5 100644 --- a/Socket/Protocols/UN/UNAddress.hh +++ b/Socket/Protocols/UN/UNAddress.hh @@ -48,16 +48,17 @@ namespace senf { explicit UNAddress(boost::filesystem::path);///< Construct an address constant from given path static UNAddress fromString(std::string & s); ///< Convert string to address by interpreting the string as path static UNAddress fromPath(boost::filesystem::path & p);///< Convert path to address - static std::string pathString(); ///< Return the path of the address as string + UNAddress clone(); ///< Clone object + std::string pathString() const; ///< Return the path of the address as string /** \brief Base-class for UNAddress exceptions */ struct AddressException : public std::exception {}; private: - static boost::filesystem::path path; + boost::filesystem::path path; }; -const std::ostream & operator<<(std::ostream & os, UNAddress const & addr); +std::ostream & operator<<(std::ostream & os, UNAddress const & addr); } ///////////////////////////////hh.e//////////////////////////////////////// diff --git a/Socket/Protocols/UN/UNAddress.test.cc b/Socket/Protocols/UN/UNAddress.test.cc new file mode 100644 index 0000000000000000000000000000000000000000..d6ade16bd7d7e71dacd6f46d909719c452f6fe81 --- /dev/null +++ b/Socket/Protocols/UN/UNAddress.test.cc @@ -0,0 +1,59 @@ +// $Id$ +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief UNAddress.test unit tests */ + +//#include "UNAddress.test.hh" +//#include "UNAddress.test.ih" + +// Custom includes +#include "UNAddress.hh" +#include <boost/filesystem/path.hpp> +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#include <iostream> +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(unAddress) +{ + // das koennt sicher mehr sein... + std::string testS = "/tmp/senfTestSocket"; + boost::filesystem::path testp = boost::filesystem::path(testS); + senf::UNAddress addr1 = senf::UNAddress::fromString(testS); + senf::UNAddress addr2 = senf::UNAddress::fromPath(testp); + BOOST_CHECK( testS == addr1.pathString()); + BOOST_CHECK( testS == addr2.pathString()); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Socket/Protocols/UN/UNAddressing.cc b/Socket/Protocols/UN/UNAddressing.cc index abc278f374d98a5b3e3269c9e6897e39f72b603c..ce957e4b1f66c51ed9b5c1e445a2b8712bf175cb 100644 --- a/Socket/Protocols/UN/UNAddressing.cc +++ b/Socket/Protocols/UN/UNAddressing.cc @@ -55,6 +55,7 @@ prefix_ senf::UNSocketAddress::UNSocketAddress(boost::filesystem::path p) return senf::UNSocketAddress::UNSocketAddress(p); } prefix_ std::string senf::UNSocketAddress::path() + const { return std::string(sockAddr.sun_path); } @@ -80,7 +81,6 @@ prefix_ sockaddr const * senf::UNSocketAddress::sockaddr_p() } prefix_ unsigned senf::UNSocketAddress::sockaddr_len() - const { return sizeof(sockAddr); } diff --git a/Socket/Protocols/UN/UNAddressing.hh b/Socket/Protocols/UN/UNAddressing.hh index 25b02d96bc5575ad7fa512c74c203888cc9b4383..f30cfdd82e7dd18b15880fe3f95fe748eb59f6f2 100644 --- a/Socket/Protocols/UN/UNAddressing.hh +++ b/Socket/Protocols/UN/UNAddressing.hh @@ -42,7 +42,7 @@ namespace senf { /** \brief Unix domain socket address - UNSocketAddress wraps the standard sockaddr_in datatype. It provides simple accessor methods + UNSocketAddress wraps the standard sockaddr_un datatype. It provides simple accessor methods to access the path. \implementation This implementation is based on sockaddr_un. @@ -59,14 +59,13 @@ namespace senf { ///< Construct an address constant from given path static UNSocketAddress from_string(std::string const s); ///< Create UNSocketAddress from string static UNSocketAddress from_path(boost::filesystem::path const p); ///< Create UNSocketAddress from path - static std::string path(); ///< Return path as string - static sockaddr_un sockaddr(); - - struct sockaddr * sockaddr_p(); + std::string path() const ; ///< Return path as string + struct sockaddr_un sockaddr(); + struct sockaddr * sockaddr_p() ; struct sockaddr const * sockaddr_p() const; - unsigned sockaddr_len() const; + unsigned sockaddr_len(); private: - static struct sockaddr_un sockAddr; + struct sockaddr_un sockAddr; }; /** \brief Write path os diff --git a/Socket/Protocols/UN/UNAddressing.o b/Socket/Protocols/UN/UNAddressing.o new file mode 100644 index 0000000000000000000000000000000000000000..417b79b4e549314c9bb9bcebcfc7acff861e6872 Binary files /dev/null and b/Socket/Protocols/UN/UNAddressing.o differ diff --git a/Socket/Protocols/UN/UNAddressing.test.cc b/Socket/Protocols/UN/UNAddressing.test.cc new file mode 100644 index 0000000000000000000000000000000000000000..b3b76e80f04a2ed6c93da2c572f50cfa925105a1 --- /dev/null +++ b/Socket/Protocols/UN/UNAddressing.test.cc @@ -0,0 +1,61 @@ +// $Id$ +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief UNAddressing.test unit tests */ + +//#include "UNAddressing.test.hh" +//#include "UNAddressing.test.ih" + +// Custom includes +#include "UNAddressing.hh" + +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#include <sys/socket.h> +#include <sys/un.h> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(unSocketAddress) +{ + std::string testS = "/tmp/senfTestSocket"; + senf::UNSocketAddress addr (testS) ; + int mySock = socket(AF_UNIX, SOCK_DGRAM, 0); + if (bind(mySock, addr.sockaddr_p(), addr.sockaddr_len())) { + std::cout << "Error while binding name to unix socket" << std::endl; + } + +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Socket/Protocols/UN/UNAddressing.test.cc~ b/Socket/Protocols/UN/UNAddressing.test.cc~ new file mode 100644 index 0000000000000000000000000000000000000000..7f224cfec01df9ada2fbcdb695bda1e464763e53 --- /dev/null +++ b/Socket/Protocols/UN/UNAddressing.test.cc~ @@ -0,0 +1,61 @@ +// $Id$ +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief UNAddressing.test unit tests */ + +//#include "UNAddressing.test.hh" +//#include "UNAddressing.test.ih" + +// Custom includes +#include "UNAddressing.hh" + +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#include <sys/socket.h> +#include <sys/un.h> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(unSocketAddress) +{ + std::string testS = "/tmp/senfTestSocket"; + senf::UNSocketAddress addr (testS) ; + mySock = socket(AF_UNIX, SOCK_DGRAM, 0); + if (bind(mySock, addr.sockaddr_p(), addr.sockaddr_len())) { + std::cout << "Error while binding name to unix socket" std::endl; + } + +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Socket/Protocols/UN/UNDatagramSocketHandle.hh b/Socket/Protocols/UN/UNDatagramSocketHandle.hh index 458a9589e54f7f9d37e9dfd513507952be501aaa..0956525a26ece5aab0de4aabf95ffc09bb262f94 100644 --- a/Socket/Protocols/UN/UNDatagramSocketHandle.hh +++ b/Socket/Protocols/UN/UNDatagramSocketHandle.hh @@ -110,7 +110,7 @@ namespace senf { typedef MakeSocketPolicy< UNDatagramSocket_Policy, UNAddressingPolicy - >::policy UDPv6Socket_Policy; + >::policy UNDatagramSocket_Policy; } ///////////////////////////////hh.e//////////////////////////////////////// //#include "UNDatagramSocketHandle.cci" diff --git a/Socket/Protocols/UN/UNDatagramSocketHandle.test.cc b/Socket/Protocols/UN/UNDatagramSocketHandle.test.cc new file mode 100644 index 0000000000000000000000000000000000000000..d6485740be29e12b8b76601e4203b4f58ca43bcb --- /dev/null +++ b/Socket/Protocols/UN/UNDatagramSocketHandle.test.cc @@ -0,0 +1,56 @@ +// $Id$ +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief UNDatagramSocketHandle.test unit tests */ + +//#include "UNDatagramSocketHandle.test.hh" +//#include "UNDatagramSocketHandle.test.ih" + +// Custom includes +#include "UNDatagramSocketHandle.hh" + +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(unDatagramSocketHandle) +{ + std::string testS = "/tmp/senfTestSocket"; + senf::UNSocketAddress addr (testS) ; + //senf::UNDatagramSocketHandle init_client(addr); + senf::UNDatagramClientSocketHandle inputSocket(senf::UNSocketAddress(tests)); +} + + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Socket/Protocols/UN/UNProtocol.cc b/Socket/Protocols/UN/UNProtocol.cc index d3afe3f38d32fc3f25a9f6b94ceaf9ec9d7e27cf..d04192d91366f17e24fe403099c1fae5000ba304 100644 --- a/Socket/Protocols/UN/UNProtocol.cc +++ b/Socket/Protocols/UN/UNProtocol.cc @@ -33,14 +33,14 @@ prefix_ void senf::UNProtocol::connect(UNSocketAddress const & address) const { - if(::connect(body().fd(), address.sockaddr_p(), sizeof(address.sockaddr())) < 0) + if(::connect(body().fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0) throw SystemException(errno); } prefix_ void senf::UNProtocol::bind(UNSocketAddress const & address) const { - if(::bind(body().fd(), address.sockaddr_p(), sizeof(address.sockaddr())) < 0) + if(::bind(body().fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0) throw SystemException(errno); } diff --git a/Socket/Protocols/UN/UNProtocol.test.cc b/Socket/Protocols/UN/UNProtocol.test.cc new file mode 100644 index 0000000000000000000000000000000000000000..5ab47b6fc9629467b1893149e3e0827417919842 --- /dev/null +++ b/Socket/Protocols/UN/UNProtocol.test.cc @@ -0,0 +1,54 @@ +// $Id$ +// +// Copyright (C) 2007 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief UNProtocol.test unit tests */ + +//#include "UNProtocol.test.hh" +//#include "UNProtocol.test.ih" + +// Custom includes +#include "UNProtocol.hh" + +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(unProtocol) +{ + std::string testS = "/tmp/senfTestSocket"; + //zZ leer +} + + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Socket/Protocols/UN/main.test.cc b/Socket/Protocols/UN/main.test.cc new file mode 100644 index 0000000000000000000000000000000000000000..91e601da22f5802d9132796553153d6b355e2ced --- /dev/null +++ b/Socket/Protocols/UN/main.test.cc @@ -0,0 +1,49 @@ +// $Id: main.test.cc 296 2007-07-10 20:39:34Z g0dil $ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <stefan.bund@fokus.fraunhofer.de> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +// Definition of non-inline non-template functions + +//#include "test.hh" +//#include "test.ih" + +// Custom includes +#define BOOST_AUTO_TEST_MAIN +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 +// End: