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()
40 template <class Policy>
41 prefix_ void satcom::lib::ClientSocketHandle<Policy>::read(std::string & buffer)
43 unsigned nread = available();
44 // FIXME: This is not necessary correct and more or less a hack ...
45 buffer.assign(nread,0);
46 unsigned rv = this->read(const_cast<char *>(buffer.data()),nread);
48 buffer.erase(buffer.begin()+rv,buffer.end());
51 template <class Policy>
52 prefix_ std::pair<std::string, typename Policy::AddressingPolicy::Address>
53 satcom::lib::ClientSocketHandle<Policy>::readfrom()
56 typename Policy::AddressingPolicy::Address addr;
57 this->readfrom(rv,addr);
58 return std::make_pair(rv,addr);
61 template <class Policy>
62 prefix_ void satcom::lib::ClientSocketHandle<Policy>::
63 readfrom(std::string & buffer, typename Policy::AddressingPolicy::Address & from)
65 unsigned nread = available();
66 // FIXME: This is not necessary correct and more or less a hack ...
67 buffer.assign(nread,0);
68 unsigned rv = this->readfrom(const_cast<char *>(buffer.data()), nread, from);
70 buffer.erase(buffer.begin()+rv,buffer.end());
73 template <class Policy>
74 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::write(std::string const & data)
76 unsigned written = this->write(data.data(),data.size());
78 throw SystemException(EPIPE);
79 // This implementation ensures, we only call blocking() when
80 // necessary (since it incurs a system call overhead ...)
81 if (written < data.size() && this->blocking())
82 // We need to enforce in the WritePolicy implementation, that
83 // DatagramFramingPolicy sockets will ALWAYS either write the
84 // complete datagram or nothing at all
85 while (written < data.size()) {
86 unsigned n = this->write(data.data()+written,data.size()-written);
88 throw SystemException(EPIPE);
94 template <class Policy>
95 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::available()
97 unsigned nread = this->protocol().available();
98 if (nread == 0 && this->blocking()) {
100 nread = this->protocol().available();
105 ///////////////////////////////ct.e////////////////////////////////////////
111 // c-file-style: "satcom"