4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.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 StreamableString class is used to simplify creating a text representation of
48 arbitrary values. StreamableString 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 StreamableString : public std::string
59 using std::string::operator=;
62 StreamableString & operator<<(T const & other);
64 /**< This operator will assign the string from any
65 arbitrary type. It will use boost::lexical_cast to
66 convert the argument to its string representation.
68 If the string is non-empty, an additional separating
69 comma is added to the string. */
71 StreamableString & operator<<(bool v); ///< Bool assignment
72 /**< The bool assignment is defined explicitly to use a
73 specialized representation (the strings 'true' and
79 typedef std::map< std::string, detail::StreamableString > SocketStateMap;
82 /** \brief Helper to convert SocketStateMap to multiline string representation
85 std::string dumpState(SocketStateMap const & map);
88 /** \brief SocketHandle referenced body
92 senf::SocketBody is the extended (relatively to senf::FileBody) body of
93 senf::SocketHandle. Every SocketHandle must have a SocketBody as it's body (and not a simple
94 FileBody). The casting and conversion operators defined will ensure this if used
95 properly. If this invariant is violated, your Program will probably crash.
99 public senf::pool_alloc_mixin<SocketBody>
102 using senf::pool_alloc_mixin<SocketBody>::operator new;
103 using senf::pool_alloc_mixin<SocketBody>::operator delete;
105 ///////////////////////////////////////////////////////////////////////////
108 typedef boost::intrusive_ptr<SocketBody> ptr;
110 ///////////////////////////////////////////////////////////////////////////
111 ///\name Structors and default members
114 SocketBody(std::auto_ptr<SocketProtocol> protocol, bool isServer);
116 \param protocol Protocol class implementing the desired
118 \param isServer \c true, if this socket is a server
119 socket, false otherwise */
120 SocketBody(std::auto_ptr<SocketProtocol> protocol, bool isServer, int fd);
122 \param protocol Protocol class implementing the desired
124 \param isServer \c true, if this socket is a server
125 socket, false otherwise
126 \param fd socket file descriptor */
129 // no conversion constructors
132 ///////////////////////////////////////////////////////////////////////////
134 SocketProtocol const & protocol() const;
135 ///< Access the protocol instance
136 bool isServer(); ///< Check socket type
137 /**< \return \c true, if this is a server socket, \c false
140 void state(SocketStateMap & map, unsigned lod);
143 virtual void v_close(); ///< Close socket
144 /**< This override will automatically \c shutdown() the
145 socket whenever it is closed.
146 \throws senf::SystemException */
147 virtual void v_terminate(); ///< Forcibly close socket
148 /**< This override will automatically \c shutfown() the
149 socket whenever it is called. Additionally it will
150 disable SO_LINGER to ensure, that v_terminate will not
151 block. Like the overriden method, this member will ignore
152 failures and will never throw. It therefore safe to be
153 called from a destructor. */
154 virtual bool v_eof() const; ///< Check for eof condition
155 /**< Since the eof check for sockets is very protocol
156 dependent, this member will forward the call to
157 senf::SocketPolicy::eof() */
159 boost::scoped_ptr<SocketProtocol> protocol_;
165 ///////////////////////////////ih.e////////////////////////////////////////
172 // c-file-style: "senf"
173 // indent-tabs-mode: nil
174 // ispell-local-dictionary: "american"
175 // compile-command: "scons -u test"
176 // comment-column: 40