4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Definition of non-inline template functions
25 //#include "ClientSocketHandle.ih"
30 ///////////////////////////////ct.p////////////////////////////////////////
32 template <class Policy>
33 prefix_ std::string satcom::lib::ClientSocketHandle<Policy>::read(unsigned limit)
40 template <class Policy>
41 prefix_ void satcom::lib::ClientSocketHandle<Policy>::read(std::string & buffer, unsigned limit)
43 unsigned nread = available();
44 if (limit>0 && nread>limit)
46 // FIXME: This is not necessary correct and more or less a hack ...
47 buffer.assign(nread,0);
48 unsigned rv = this->read(const_cast<char *>(buffer.data()),nread);
50 buffer.erase(buffer.begin()+rv,buffer.end());
53 template <class Policy>
54 prefix_ std::pair<std::string, typename Policy::AddressingPolicy::Address>
55 satcom::lib::ClientSocketHandle<Policy>::readfrom()
58 typename Policy::AddressingPolicy::Address addr;
59 this->readfrom(rv,addr);
60 return std::make_pair(rv,addr);
63 template <class Policy>
64 prefix_ void satcom::lib::ClientSocketHandle<Policy>::
65 readfrom(std::string & buffer, typename Policy::AddressingPolicy::Address & from)
67 unsigned nread = available();
68 // FIXME: This is not necessary correct and more or less a hack ...
69 buffer.assign(nread,0);
70 unsigned rv = this->readfrom(const_cast<char *>(buffer.data()), nread, from);
72 buffer.erase(buffer.begin()+rv,buffer.end());
75 template <class Policy>
76 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::write(std::string const & data)
78 unsigned written = this->write(data.data(),data.size());
80 throw SystemException(EPIPE);
81 // This implementation ensures, we only call blocking() when
82 // necessary (since it incurs a system call overhead ...)
83 if (written < data.size() && this->blocking())
84 // We need to enforce in the WritePolicy implementation, that
85 // DatagramFramingPolicy sockets will ALWAYS either write the
86 // complete datagram or nothing at all
87 while (written < data.size()) {
88 unsigned n = this->write(data.data()+written,data.size()-written);
90 throw SystemException(EPIPE);
96 template <class Policy>
97 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::available()
99 unsigned nread = this->protocol().available();
100 if (nread == 0 && this->blocking()) {
101 this->waitReadable();
102 nread = this->protocol().available();
107 ///////////////////////////////ct.e////////////////////////////////////////
113 // c-file-style: "satcom"