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.
24 \brief SocketHandle internal header
27 #ifndef IH_SocketHandle_
28 #define IH_SocketHandle_ 1
33 #include <boost/scoped_ptr.hpp>
34 #include "FileHandle.hh"
36 ///////////////////////////////ih.p////////////////////////////////////////
45 /** \brief String supporting automatic type conversion
47 The ConvertibleString class is used to simplify creating a text representation of
48 arbitrary values. ConvertibleString is an ordinary string with an additional constructor
49 which allows constructing the string from any arbitrary, streamable type.
51 \note It is generally not advisable to derive from the standard library container
52 classes. However, in this concrete case, the derivation is safe since only the
53 additional functionality is added. It is absolutely safe to convert the derived class
54 back to the base type.
56 class ConvertibleString : public std::string
60 ConvertibleString(bool v); ///< Bool conversion constructor
61 /**< The bool conversion is defined explicitly to use a
62 specialized representation (the strings 'true' and
65 ConvertibleString(T const & other);
66 ///< Conversion constructor
67 /**< This constructor will assign the string from any
68 arbitrary type. It will use boost::lexical_cast to
69 convert the argument to its string representation. */
72 ConvertibleString & operator+= (ConvertibleString const & other);
73 ///< Add additional values with separator
74 /**< This operator facilitates the representation of
75 multiple values in a single string. Each value is first
76 converted to a string (using the type conversion
77 machinery of C++ and the ConvertibleString conversion
78 constructors). It is then appended to the current string
79 with ', ' as a separator (if the current string is
85 typedef std::map< std::string, detail::ConvertibleString > SocketStateMap;
88 /** \brief Helper to convert SocketStateMap to multiline string representation
91 std::string dumpState(SocketStateMap const & map);
94 /** \brief SocketHandle referenced body
98 senf::SocketBody is the extended (relatively to senf::FileBody) body of
99 senf::SocketHandle. Every SocketHandle must have a SocketBody as it's body (and not a simple
100 FileBody). The casting and conversion operators defined will ensure this if used
101 properly. If this invariant is violated, your Program will probably crash.
107 ///////////////////////////////////////////////////////////////////////////
110 typedef boost::intrusive_ptr<SocketBody> ptr;
112 ///////////////////////////////////////////////////////////////////////////
113 ///\name Structors and default members
116 SocketBody(std::auto_ptr<SocketProtocol> protocol, bool isServer);
118 \param protocol Protocol class implementing the desired
120 \param isServer \c true, if this socket is a server
121 socket, false otherwise */
122 SocketBody(std::auto_ptr<SocketProtocol> protocol, bool isServer, int fd);
124 \param protocol Protocol class implementing the desired
126 \param isServer \c true, if this socket is a server
127 socket, false otherwise
128 \param fd socket file descriptor */
131 // no conversion constructors
134 ///////////////////////////////////////////////////////////////////////////
136 SocketProtocol const & protocol() const;
137 ///< Access the protocol instance
138 bool isServer(); ///< Check socket type
139 /**< \return \c true, if this is a server socket, \c false
142 void state(SocketStateMap & map, unsigned lod);
145 virtual void v_close(); ///< Close socket
146 /**< This override will automatically \c shutdown() the
147 socket whenever it is closed.
148 \throws senf::SystemException */
149 virtual void v_terminate(); ///< Forcibly close socket
150 /**< This override will automatically \c shutfown() the
151 socket whenever it is called. Additionally it will
152 disable SO_LINGER to ensure, that v_terminate will not
153 block. Like the overriden method, this member will ignore
154 failures and will never throw. It therefore safe to be
155 called from a destructor. */
156 virtual bool v_eof() const; ///< Check for eof condition
157 /**< Since the eof check for sockets is very protocol
158 dependent, this member will forward the call to
159 senf::SocketPolicy::eof() */
161 boost::scoped_ptr<SocketProtocol> protocol_;
167 ///////////////////////////////ih.e////////////////////////////////////////
174 // c-file-style: "senf"
175 // indent-tabs-mode: nil
176 // ispell-local-dictionary: "american"