Fixed whitespace in all files (no tabs)
[senf.git] / Socket / ClientSocketHandle.ct
index 50c80a8..17a518e 100644 (file)
@@ -1,6 +1,6 @@
 // $Id$
 //
-// Copyright (C) 2006 
+// Copyright (C) 2006
 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
@@ -20,7 +20,9 @@
 // Free Software Foundation, Inc.,
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-// Definition of non-inline template functions
+/** \file
+    \brief ClientSocketHandle non-inline template implementation
+ */
 
 //#include "ClientSocketHandle.ih"
 
@@ -30,7 +32,7 @@
 ///////////////////////////////ct.p////////////////////////////////////////
 
 template <class Policy>
-prefix_ std::string satcom::lib::ClientSocketHandle<Policy>::read(unsigned limit)
+prefix_ std::string senf::ClientSocketHandle<Policy>::read(unsigned limit)
 {
     std::string rv;
     this->read(rv,limit);
@@ -38,12 +40,12 @@ prefix_ std::string satcom::lib::ClientSocketHandle<Policy>::read(unsigned limit
 }
 
 template <class Policy>
-prefix_ void satcom::lib::ClientSocketHandle<Policy>::read(std::string & buffer, unsigned limit)
+prefix_ void senf::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 ...
+    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);
     if (rv < nread)
@@ -52,7 +54,7 @@ prefix_ void satcom::lib::ClientSocketHandle<Policy>::read(std::string & buffer,
 
 template <class Policy>
 prefix_ std::pair<std::string, typename Policy::AddressingPolicy::Address>
-satcom::lib::ClientSocketHandle<Policy>::readfrom()
+senf::ClientSocketHandle<Policy>::readfrom()
 {
     std::string rv;
     typename Policy::AddressingPolicy::Address addr;
@@ -61,11 +63,11 @@ satcom::lib::ClientSocketHandle<Policy>::readfrom()
 }
 
 template <class Policy>
-prefix_ void satcom::lib::ClientSocketHandle<Policy>::
+prefix_ void senf::ClientSocketHandle<Policy>::
 readfrom(std::string & buffer, typename Policy::AddressingPolicy::Address & from)
 {
     unsigned nread = available();
-    // FIXME: This is not necessary correct and more or less a hack ...
+    /** \fixme This is not necessary correct and more or less a hack ... */
     buffer.assign(nread,0);
     unsigned rv = this->readfrom(const_cast<char *>(buffer.data()), nread, from);
     if (rv < nread)
@@ -73,7 +75,7 @@ readfrom(std::string & buffer, typename Policy::AddressingPolicy::Address & from
 }
 
 template <class Policy>
-prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::write(std::string const & data)
+prefix_ unsigned senf::ClientSocketHandle<Policy>::write(std::string const & data)
 {
     unsigned written = this->write(data.data(),data.size());
     if (written == 0)
@@ -85,7 +87,7 @@ prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::write(std::string cons
         // DatagramFramingPolicy sockets will ALWAYS either write the
         // complete datagram or nothing at all
         while (written < data.size()) {
-            unsigned n = this->write(data.data()+written,data.size()-written); 
+            unsigned n = this->write(data.data()+written,data.size()-written);
             if (n == 0)
                 throw SystemException(EPIPE);
             written += n;
@@ -94,12 +96,18 @@ prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::write(std::string cons
 }
 
 template <class Policy>
-prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::available()
+prefix_ unsigned senf::ClientSocketHandle<Policy>::available()
 {
     unsigned nread = this->protocol().available();
     if (nread == 0 && this->blocking()) {
-            this->waitReadable();
-            nread = this->protocol().available();
+        // We have to block explicitly here so we can return the
+        // number of bytes available explicitly. If no more date can
+        // be expected to arive (i.e. the other end has closed the
+        // connection), the socket will always be in the readable
+        // state. This is the only case when available() will return
+        // 0.
+        this->waitReadable();
+        nread = this->protocol().available();
     }
     return nread;
 }
@@ -110,5 +118,8 @@ prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::available()
 \f
 // Local Variables:
 // mode: c++
-// c-file-style: "satcom"
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
 // End: