X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FClientSocketHandle.ct;h=17a518ef6da176338612ac04cdaa0b8d22a1d70d;hb=9a988902090d28007578e93bffd809f6bd913155;hp=1e7fa7b93dcca55316ad338d8ccdd846875566fa;hpb=c52cd7d87dbb525c1267aad27391b8b7365dbb57;p=senf.git diff --git a/Socket/ClientSocketHandle.ct b/Socket/ClientSocketHandle.ct index 1e7fa7b..17a518e 100644 --- a/Socket/ClientSocketHandle.ct +++ b/Socket/ClientSocketHandle.ct @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2006 +// Copyright (C) 2006 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) // Stefan Bund @@ -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,18 +32,20 @@ ///////////////////////////////ct.p//////////////////////////////////////// template -prefix_ std::string satcom::lib::ClientSocketHandle::read() +prefix_ std::string senf::ClientSocketHandle::read(unsigned limit) { std::string rv; - this->read(rv); + this->read(rv,limit); return rv; } template -prefix_ void satcom::lib::ClientSocketHandle::read(std::string & buffer) +prefix_ void senf::ClientSocketHandle::read(std::string & buffer, unsigned limit) { unsigned nread = available(); - // 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(buffer.data()),nread); if (rv < nread) @@ -50,7 +54,7 @@ prefix_ void satcom::lib::ClientSocketHandle::read(std::string & buffer) template prefix_ std::pair -satcom::lib::ClientSocketHandle::readfrom() +senf::ClientSocketHandle::readfrom() { std::string rv; typename Policy::AddressingPolicy::Address addr; @@ -59,11 +63,11 @@ satcom::lib::ClientSocketHandle::readfrom() } template -prefix_ void satcom::lib::ClientSocketHandle:: +prefix_ void senf::ClientSocketHandle:: 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(buffer.data()), nread, from); if (rv < nread) @@ -71,7 +75,7 @@ readfrom(std::string & buffer, typename Policy::AddressingPolicy::Address & from } template -prefix_ unsigned satcom::lib::ClientSocketHandle::write(std::string const & data) +prefix_ unsigned senf::ClientSocketHandle::write(std::string const & data) { unsigned written = this->write(data.data(),data.size()); if (written == 0) @@ -83,7 +87,7 @@ prefix_ unsigned satcom::lib::ClientSocketHandle::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; @@ -92,12 +96,18 @@ prefix_ unsigned satcom::lib::ClientSocketHandle::write(std::string cons } template -prefix_ unsigned satcom::lib::ClientSocketHandle::available() +prefix_ unsigned senf::ClientSocketHandle::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; } @@ -108,5 +118,8 @@ prefix_ unsigned satcom::lib::ClientSocketHandle::available() // Local Variables: // mode: c++ -// c-file-style: "satcom" +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" // End: