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 non-template functions
25 #include "SocketHandle.hh"
26 #include "SocketHandle.ih"
30 #include <sys/socket.h>
31 #include "Utils/TypeInfo.hh"
33 //#include "SocketHandle.mpp"
35 ///////////////////////////////cc.p////////////////////////////////////////
37 prefix_ void satcom::lib::SocketBody::v_close()
39 if (::shutdown(fd(),SHUT_RDWR) < 0)
40 throw SystemException(errno);
41 if (::close(fd()) < 0)
42 throw SystemException(errno);
45 prefix_ void satcom::lib::SocketBody::v_terminate()
51 // We purposely IGNORE any errors: this method is used to try and
52 // terminate the connection ignoring any possible problems
54 ::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling));
55 ::shutdown(fd(),SHUT_RDWR);
59 prefix_ bool satcom::lib::SocketBody::v_eof()
62 return protocol().eof();
65 prefix_ void satcom::lib::SocketBody::state(SocketStateMap & map, unsigned lod)
67 map["file.handle"] = fd();
68 map["file.refcount"] = refcount();
69 map["socket.server"] = isServer();
70 map["socket.protocol"] = prettyName(typeid(protocol()));
71 map["socket.policy"] = prettyName(typeid(protocol().policy()));
72 protocol().state(map,lod);
75 ///////////////////////////////////////////////////////////////////////////
76 // satcom::lib::detail::StateMapOrdering
79 bool contains(std::string::iterator b, std::string::iterator e, char c)
88 prefix_ bool satcom::lib::detail::StateMapOrdering::operator()(std::string a1, std::string a2)
91 std::string::iterator i1 (a1.begin());
92 std::string::iterator const i1_end (a1.end());
93 std::string::iterator i2 (a2.begin());
94 std::string::iterator const i2_end (a2.end());
95 for(; i1 != i1_end && i2 != i2_end && *i1 == *i2; ++i1, ++i2) ;
98 // the strings are equal
100 if (contains(i2,i2_end,'.'))
101 // the longer string is a sub-'directory' of the shorter
105 else if (i2 == i2_end) { // && i1 != i1_end
106 if (contains(i1,i1_end,'.'))
107 // the longer string is a sub-'directory' of the shorter
111 if (contains(i1,i1_end,'.')) {
112 if (contains(i2,i2_end,'.'))
116 else if (contains(i2,i2_end,'.'))
121 prefix_ std::string satcom::lib::detail::dumpState(SocketStateMap const & map)
124 SocketStateMap::const_iterator i (map.begin());
125 SocketStateMap::const_iterator i_end (map.end());
126 for (; i != i_end; ++i)
127 s << i->first << ": " << i->second << "\n";
131 template <class Policy>
132 prefix_ std::ostream & satcom::lib::operator<<(std::ostream & os, SocketHandle<Policy> handle)
134 os << handle.dumpState();
138 ///////////////////////////////cc.e////////////////////////////////////////
140 //#include "SocketHandle.mpp"
145 // c-file-style: "satcom"