]> git.llucax.com Git - software/posixx.git/commitdiff
Add socket addresses ostream formatting
authorLeandro Lucarella <llucarella@integratech.com.ar>
Mon, 10 Nov 2008 16:03:04 +0000 (14:03 -0200)
committerLeandro Lucarella <llucarella@integratech.com.ar>
Thu, 13 Nov 2008 21:18:33 +0000 (19:18 -0200)
src/linux/tipc/print.hpp [new file with mode: 0644]
src/socket/inet/print.hpp [new file with mode: 0644]
src/socket/unix/print.hpp [new file with mode: 0644]
test/linux/tipc/common.hpp
test/socket/inet/common.hpp
test/socket/unix/common.hpp

diff --git a/src/linux/tipc/print.hpp b/src/linux/tipc/print.hpp
new file mode 100644 (file)
index 0000000..3b3d642
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef POSIXX_LINUX_TIPC_PRINT_HPP_
+#define POSIXX_LINUX_TIPC_PRINT_HPP_
+
+#include "../tipc.hpp" // posixx::linux::tipc::sockaddr
+#include <ostream> // std::ostream
+
+inline
+std::ostream& operator << (std::ostream& os,
+               const posixx::linux::tipc::sockaddr& sa) throw()
+{
+       using posixx::linux::tipc::sockaddr;
+       os << "tipc::sockaddr(scope=" << unsigned(sa.scope) << ", ";
+       switch (sa.type())
+       {
+       case sockaddr::ID:
+               os << "id(ref=" << sa.addr.id.ref
+                               << ", node=" << sa.addr.id.node << ")";
+               break;
+       case sockaddr::NAME:
+               os << "name(type=" << sa.addr.name.name.type
+                               << ", instance=" << sa.addr.name.name.instance
+                               << ", domain=" << sa.addr.name.domain << ")";
+               break;
+       case sockaddr::NAMESEQ:
+               os << "nameseq(type=" << sa.addr.nameseq.type
+                               << ", lower=" << sa.addr.nameseq.lower
+                               << ", upper=" << sa.addr.nameseq.upper << ")";
+               break;
+       default:
+               os << "UNKNOWN!";
+       }
+       return os << ")";
+}
+
+#endif // POSIXX_LINUX_TIPC_PRINT_HPP_
diff --git a/src/socket/inet/print.hpp b/src/socket/inet/print.hpp
new file mode 100644 (file)
index 0000000..7c61e26
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef POSIXX_SOCKET_INET_PRINT_HPP_
+#define POSIXX_SOCKET_INET_PRINT_HPP_
+
+#include "../inet.hpp" // posixx::socket::inet::sockaddr
+#include <ostream> // std::ostream
+
+inline
+std::ostream& operator << (std::ostream& os,
+               const posixx::socket::inet::sockaddr& sa) throw()
+{
+       return os << "inet::sockaddr(port=" << ntohs(sa.sin_port)
+                       << ", addr=" << inet_ntoa(sa.sin_addr) << ")";
+}
+
+#endif // POSIXX_SOCKET_INET_PRINT_HPP_
diff --git a/src/socket/unix/print.hpp b/src/socket/unix/print.hpp
new file mode 100644 (file)
index 0000000..3a540f2
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef POSIXX_SOCKET_UNIX_PRINT_HPP_
+#define POSIXX_SOCKET_UNIX_PRINT_HPP_
+
+#include "../inet.hpp" // posixx::socket::inet::sockaddr
+#include <ostream> // std::ostream
+
+inline
+std::ostream& operator << (std::ostream& os,
+               const posixx::socket::unix::sockaddr& sa) throw()
+{
+       return os << "unix::sockaddr(path=" << sa.sun_path << ")";
+}
+
+#endif // POSIXX_SOCKET_UNIX_PRINT_HPP_
index 81cf51eaaae1aa30d01b47a4a724ecf805289f60..261966382c70a47c7784006df5288d66d0f72dd2 100644 (file)
@@ -2,40 +2,12 @@
 #define TEST_LINUX_TIPC_COMMON_HPP_
 
 #include <posixx/linux/tipc.hpp> // posixx::linux::tipc
-#include <ostream> // std::ostream
+#include <posixx/linux/tipc/print.hpp> // address output formatting
 
 #define PTYPE 10000
 #define INST1 10001
 #define INST2 10002
 
-static inline
-std::ostream& operator << (std::ostream& os,
-               const posixx::linux::tipc::sockaddr& sa) throw()
-{
-       using posixx::linux::tipc::sockaddr;
-       os << "tipc::sockaddr(scope=" << unsigned(sa.scope) << ", ";
-       switch (sa.type())
-       {
-       case sockaddr::ID:
-               os << "id(ref=" << sa.addr.id.ref
-                               << ", node=" << sa.addr.id.node << ")";
-               break;
-       case sockaddr::NAME:
-               os << "name(type=" << sa.addr.name.name.type
-                               << ", instance=" << sa.addr.name.name.instance
-                               << ", domain=" << sa.addr.name.domain << ")";
-               break;
-       case sockaddr::NAMESEQ:
-               os << "nameseq(type=" << sa.addr.nameseq.type
-                               << ", lower=" << sa.addr.nameseq.lower
-                               << ", upper=" << sa.addr.nameseq.upper << ")";
-               break;
-       default:
-               os << "UNKNOWN!";
-       }
-       return os << ")";
-}
-
 // no need to clean addresses
 #define clean_test_address(socket, addr)
 
index 5dd8612f7de05db4574478bbb1048f083916b0c6..9884c7ef0a4ce7b8dddc1704f8b621f5a343f69d 100644 (file)
@@ -2,6 +2,7 @@
 #define TEST_SOCKET_IP_COMMON_HPP_
 
 #include <posixx/socket/inet.hpp> // posixx::socket::inet
+#include <posixx/socket/inet/print.hpp> // address ostream formatting
 #include <posixx/socket/opt.hpp> // posixx::socket::opt::REUSEADDR
 #include <ostream> // std::ostream
 
@@ -9,15 +10,6 @@
 #define PORT1 10001
 #define PORT2 10002
 
-static inline
-std::ostream& operator << (std::ostream& os,
-               const posixx::socket::inet::sockaddr& sa) throw()
-{
-       return os << "inet::sockaddr(family=" << sa.sin_family
-               << ", port=" << ntohs(sa.sin_port)
-               << ", addr=" << inet_ntoa(sa.sin_addr) << ")";
-}
-
 static inline
 void clean_test_address(posixx::socket::inet::socket& socket,
                const posixx::socket::inet::sockaddr& addr)
index e80f1a635de33dd9f9964305c6362815c6f10db0..4686974d5bd5c79e8a787ac0681b246e8626b8ba 100644 (file)
@@ -2,6 +2,7 @@
 #define TEST_SOCKET_UNIX_COMMON_HPP_
 
 #include <posixx/socket/unix.hpp> // posixx::socket::unix
+#include <posixx/socket/unix/print.hpp> // address ostream formatting
 #include <boost/test/unit_test.hpp> // unit testing stuff
 #include <ostream> // std::ostream
 #include <unistd.h> // unlink
 #define PATH1 PATH "1"
 #define PATH2 PATH "2"
 
-static inline
-std::ostream& operator << (std::ostream& os,
-               const posixx::socket::unix::sockaddr& sa) throw()
-{
-       return os << "unix::sockaddr(family=" << sa.sun_family
-               << ", path=" << sa.sun_path << ")";
-}
-
 static inline
 void clean_test_address(posixx::socket::unix::socket& socket,
                const posixx::socket::unix::sockaddr& addr)