Socket: Move protocol into the socket body (as private base class) and allow non...
[senf.git] / Socket / SocketHandle.cci
index c25d09f..896d13a 100644 (file)
 #define prefix_ inline
 ///////////////////////////////cci.p///////////////////////////////////////
 
-prefix_ senf::SocketBody::SocketBody(std::auto_ptr<SocketProtocol> protocol,
-                                            bool isServer)
-    : protocol_(protocol), isServer_(isServer)
-{
-    SENF_ASSERT( ! protocol_->body_ );
-    protocol_->body_ = this;
-}
+prefix_ senf::SocketBody::SocketBody(bool isServer)
+    : isServer_(isServer)
+{}
+
+prefix_ senf::SocketBody::SocketBody(bool isServer, int fd)
+    : FileBody(fd), isServer_(isServer)
+{}
 
-prefix_ senf::SocketBody::SocketBody(std::auto_ptr<SocketProtocol> protocol,
-                                            bool isServer, int fd)
-    : FileBody(fd), protocol_(protocol), isServer_(isServer)
+prefix_ senf::SocketProtocol & senf::SocketBody::protocol()
 {
-    SENF_ASSERT( ! protocol_->body_ );
-    protocol_->body_ = this;
+    return const_cast<SocketProtocol &>(v_protocol());
 }
 
 prefix_ senf::SocketProtocol const & senf::SocketBody::protocol()
     const
 {
-    return *protocol_;
+    return v_protocol();
 }
 
 prefix_ bool senf::SocketBody::isServer()
@@ -61,6 +58,18 @@ prefix_ bool senf::SocketBody::isServer()
     return isServer_;
 }
 
+prefix_ std::auto_ptr<senf::SocketBody> senf::SocketBody::clone(bool isServer)
+    const
+{
+    return protocol().clone(isServer);
+}
+
+prefix_ std::auto_ptr<senf::SocketBody> senf::SocketBody::clone(int fd, bool isServer)
+    const
+{
+    return protocol().clone(fd, isServer);
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::detail::StreamableString