added address info to socket related SystemExceptions
jkaeber [Tue, 4 Mar 2008 08:30:57 +0000 (08:30 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@726 270642c3-0616-0410-b53a-bc976706d245

Socket/Protocols/GenericAddressingPolicy.cti
Socket/Protocols/Raw/LLAddressing.cci
Socket/Protocols/Raw/LLAddressing.hh
Socket/Protocols/UN/UNAddressing.cc
Socket/Protocols/UN/UNDatagramSocketHandle.cc

index 2eaf5c8..7942fe3 100644 (file)
@@ -42,7 +42,12 @@ peer(SocketHandle<SPolicy> handle, Address & addr,
      typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type *)
 {
     addr.clear();
-    do_peer(handle,addr.sockaddr_p(),addr.sockaddr_len());
+    try {
+        do_peer(handle,addr.sockaddr_p(),addr.sockaddr_len());
+    } catch (SystemException & e) {
+        e << "; could not get peer for address \"" << addr << "\"";
+        throw;
+    }
 }
 #else
 template <class Address>
@@ -59,7 +64,12 @@ prefix_ void senf::GenericAddressingPolicy<Address>::
 connect(SocketHandle<SPolicy> handle, Address const & addr,
         typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type *)
 {
-    do_connect(handle,addr.sockaddr_p(),addr.sockaddr_len());
+    try {
+        do_connect(handle,addr.sockaddr_p(),addr.sockaddr_len());
+    } catch (SystemException & e) {
+        e << "; could not connect to address \"" << addr << "\"";
+        throw;
+    }
 }
 #else
 template <class Address>
@@ -74,14 +84,24 @@ prefix_ void senf::GenericAddressingPolicy<Address>::local(FileHandle handle,
                                                            Address & addr)
 {
     addr.clear();
-    do_local(handle,addr.sockaddr_p(),addr.sockaddr_len());
+    try {
+        do_local(handle,addr.sockaddr_p(),addr.sockaddr_len());
+    } catch (SystemException & e) {
+        e << "; could not get name for address \"" << addr << "\"";
+        throw;
+    }
 }
 
 template <class Address>
 prefix_ void senf::GenericAddressingPolicy<Address>::bind(FileHandle handle,
                                                                  Address const & addr)
 {
-    do_bind(handle,addr.sockaddr_p(),addr.sockaddr_len());
+    try {
+        do_bind(handle,addr.sockaddr_p(),addr.sockaddr_len());
+    } catch (SystemException & e) {
+        e << "; could not bind to address \"" << addr << "\"";
+        throw;
+    }
 }
 
 ///////////////////////////////cti.e///////////////////////////////////////
index 1245a10..1054845 100644 (file)
@@ -114,6 +114,13 @@ prefix_ unsigned senf::LLSocketAddress::sockaddr_len()
     return sizeof(addr_);
 }
 
+prefix_ std::ostream & senf::operator<<(std::ostream & os, LLSocketAddress const & llAddr)
+{
+    // TODO: expose more bytes from sockaddr_ll addr_
+    os << "[some LLSocketAddress]";
+    return os;
+}
+
 ///////////////////////////////cci.e///////////////////////////////////////
 #undef prefix_
 
index 2a796b5..bd82689 100644 (file)
@@ -155,6 +155,11 @@ namespace senf {
     };
 
     /// @}
+
+    /** \brief Write link layer address
+        \related LLSocketAddress
+     */
+    std::ostream & operator<<(std::ostream & os, LLSocketAddress const & llAddr);
 }
 
 ///////////////////////////////hh.e////////////////////////////////////////
index 1e01e51..8eab74b 100644 (file)
@@ -83,7 +83,7 @@ prefix_ unsigned senf::UNSocketAddress::sockaddr_len()
     return sizeof(addr_);
 }
 
-prefix_ std::ostream & operator<<(std::ostream & os,
+prefix_ std::ostream & senf::operator<<(std::ostream & os,
                                   senf::UNSocketAddress::UNSocketAddress const & addr)
 {
     os << addr.path();
index 7586683..d1b66bd 100644 (file)
@@ -48,12 +48,7 @@ prefix_ void senf::UNDatagramSocketProtocol::init_client() const
 prefix_ void senf::UNDatagramSocketProtocol::init_client(UNSocketAddress const & address) const 
 {
     init_client();
-    try {
-        clientHandle().bind(address);
-    } catch (SystemException & e) {
-        e << "; could not bind to address \"" << address.path() << "\"";
-        throw;
-    }
+    clientHandle().bind(address);
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////