add optional 'limit' argument to read
g0dil [Fri, 10 Nov 2006 23:14:58 +0000 (23:14 +0000)]
add missing retrive_filehandle overload
fix operator bool (use safe bool idiom)
add GenericSockAddr as default Address implementation

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@153 270642c3-0616-0410-b53a-bc976706d245

Socket/ClientSocketHandle.ct
Socket/ClientSocketHandle.hh
Socket/CommunicationPolicy.cc
Socket/FileHandle.cci
Socket/FileHandle.hh
Socket/GenericSockAddr.cci [new file with mode: 0644]
Socket/GenericSockAddr.hh [new file with mode: 0644]
Socket/SocketHandle.cc
Socket/SocketPolicy.ih

index 1e7fa7b..50c80a8 100644 (file)
 ///////////////////////////////ct.p////////////////////////////////////////
 
 template <class Policy>
-prefix_ std::string satcom::lib::ClientSocketHandle<Policy>::read()
+prefix_ std::string satcom::lib::ClientSocketHandle<Policy>::read(unsigned limit)
 {
     std::string rv;
-    this->read(rv);
+    this->read(rv,limit);
     return rv;
 }
 
 template <class Policy>
-prefix_ void satcom::lib::ClientSocketHandle<Policy>::read(std::string & buffer)
+prefix_ void satcom::lib::ClientSocketHandle<Policy>::read(std::string & buffer, unsigned limit)
 {
     unsigned nread = available();
+    if (limit>0 && nread>limit) 
+       nread = limit;
     // FIXME: This is not necessary correct and more or less a hack ...
     buffer.assign(nread,0);
     unsigned rv = this->read(const_cast<char *>(buffer.data()),nread);
index 0e670ab..4f9b986 100644 (file)
@@ -78,8 +78,8 @@ namespace lib {
         ///@{
 
         // read from socket (connected or unconnected)
-        std::string  read         ();
-        void         read         (std::string & buffer);
+        std::string  read         (unsigned limit=0);
+        void         read         (std::string & buffer, unsigned limit=0);
         unsigned     read         (char * buffer, unsigned size);
 
         // read from unconnected socket returning peer address
index 8523966..bc2fa33 100644 (file)
@@ -53,7 +53,6 @@ prefix_ int satcom::lib::ConnectedCommunicationPolicy::do_accept(FileHandle hand
             switch (errno) {
             case EWOULDBLOCK:
                 return -1;
-                break;
             case EINTR:
                 break;
             default:
index f633fdf..bb366ba 100644 (file)
@@ -172,18 +172,12 @@ prefix_ bool satcom::lib::FileHandle::valid()
     return body().valid();
 }
 
-prefix_ satcom::lib::FileHandle::operator bool ()
+prefix_ bool satcom::lib::FileHandle::boolean_test()
     const
 {
     return valid() && !eof();
 }
 
-prefix_ bool satcom::lib::FileHandle::operator!()
-    const
-{
-    return ! (valid() && !eof());
-}
-
 prefix_ int satcom::lib::FileHandle::fd()
     const
 {
@@ -233,6 +227,11 @@ satcom::lib::FileHandle::cast_dynamic(FileHandle handle)
     return handle;
 }
 
+prefix_ int satcom::lib::retrieve_filehandle(FileHandle handle)
+{
+    return handle.fd();
+}
+
 ///////////////////////////////cci.e///////////////////////////////////////
 #undef prefix_
 
index 3bc6155..febfa01 100644 (file)
@@ -33,6 +33,7 @@
 
 // Custom includes
 #include <memory> // std::auto_ptr
+#include "Utils/SafeBool.hh"
 
 //#include "FileHandle.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
@@ -44,6 +45,7 @@ namespace lib {
     /** \brief
      */
     class FileHandle
+       : public SafeBool<FileHandle>
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -77,8 +79,7 @@ namespace lib {
         bool eof() const;
         bool valid() const;
 
-        operator bool () const;
-        bool operator!() const;
+       bool boolean_test() const;
 
         int fd() const;
 
@@ -99,6 +100,8 @@ namespace lib {
         FileBody::ptr body_;
     };
 
+    int retrieve_filehandle(FileHandle handle);
+
 }}
 
 ///////////////////////////////hh.e////////////////////////////////////////
diff --git a/Socket/GenericSockAddr.cci b/Socket/GenericSockAddr.cci
new file mode 100644 (file)
index 0000000..7ab4372
--- /dev/null
@@ -0,0 +1,38 @@
+// $Id$
+//
+// Copyright (C) 2006 
+
+// Definition of inline non-template functions
+
+// Custom includes
+
+#define prefix_ inline
+///////////////////////////////cci.p///////////////////////////////////////
+
+prefix_ satcom::lib::GenericSockAddr::GenericSockAddr()
+{}
+
+prefix_ struct sockaddr * satcom::lib::GenericSockAddr::sockaddr_p()
+{
+    return reinterpret_cast<sockaddr *>(&addr_);
+}
+
+prefix_ struct sockaddr const * satcom::lib::GenericSockAddr::sockaddr_p()
+    const
+{
+    return reinterpret_cast<sockaddr const *>(&addr_);
+}
+
+prefix_ unsigned satcom::lib::GenericSockAddr::sockaddr_len()
+    const
+{
+    return sizeof(addr_);
+}
+
+///////////////////////////////cci.e///////////////////////////////////////
+#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// End:
diff --git a/Socket/GenericSockAddr.hh b/Socket/GenericSockAddr.hh
new file mode 100644 (file)
index 0000000..c05d158
--- /dev/null
@@ -0,0 +1,42 @@
+// $Id$
+//
+// Copyright (C) 2006 
+
+#ifndef HH_GenericSockAddr_
+#define HH_GenericSockAddr_ 1
+
+// Custom includes
+#include <sys/socket.h>
+
+//#include "GenericSockAddr.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace satcom {
+namespace lib {
+
+    class GenericSockAddr
+    {
+    public:
+       GenericSockAddr();
+       
+       struct sockaddr * sockaddr_p();
+       struct sockaddr const * sockaddr_p() const;
+       unsigned sockaddr_len() const;
+       
+    private:
+       struct ::sockaddr_storage addr_;
+    };
+
+}}
+
+///////////////////////////////hh.e////////////////////////////////////////
+#include "GenericSockAddr.cci"
+//#include "GenericSockAddr.ct"
+//#include "GenericSockAddr.cti"
+//#include "GenericSockAddr.mpp"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// End:
index 186953a..d0e7e91 100644 (file)
@@ -99,12 +99,14 @@ prefix_ bool satcom::lib::detail::StateMapOrdering::operator()(std::string a1, s
             return false;
         if (contains(i2,i2_end,'.'))
             // the longer string is a sub-'directory' of the shorter
+           // FIXME: shouldn't this be *i2 == '.' ?
             return true;
         return *i1 < *i2;
     }
     else if (i2 == i2_end) { // && i1 != i1_end
         if (contains(i1,i1_end,'.'))
             // the longer string is a sub-'directory' of the shorter
+           // FIXME: shouldn't this be *i1 == '.' ?
             return false;
         return *i1 < *i2;
     }
index 58fcba3..b60fd94 100644 (file)
@@ -46,6 +46,8 @@
 #include <boost/mpl/and.hpp>
 #include <boost/utility.hpp> // for enable_if
 
+#include "GenericSockAddr.hh"
+
 ///////////////////////////////ih.p////////////////////////////////////////
 
 namespace satcom {
@@ -62,11 +64,7 @@ namespace lib {
     {
         virtual ~ AddressingPolicyBase() {}
         
-        class Address 
-        {
-        private:
-            Address();
-        };
+       typedef GenericSockAddr Address;
     };
 
 #   define SP_DeclareBase(x1,x2,SomePolicy)                                             \