|
Boost : |
From: Giovanni P. Deretta (gpderetta_at_[hidden])
Date: 2005-12-13 07:32:55
> template <typename Service>
> class core_socket
> {
> public:
> ...
> typedef core_socket<Service> lowest_layer_type;
> lowest_layer_type& lowest_layer() { return *this; }
>
> protected:
> service_type& service_;
> impl_type impl_;
> };
>
> template <typename Service>
> class basic_stream_socket
> : private core_socket<Service>
> {
> public:
> ...
> typedef core_socket<Service> lowest_layer_type;
> lowest_layer_type& lowest_layer() { return *this; }
> };
>
> template <typename Service>
> class basic_datagram_socket
> : private core_socket<Service>
> {
> public:
> ...
> typedef core_socket<Service> lowest_layer_type;
> lowest_layer_type& lowest_layer() { return *this; }
> };
>
> The next_layer_type typedefs and next_layer() functions would
> be removed.
>
> The derived type should bring all public names from core_socket
> into its own public interface. Are using declarations OK in this
> case? If not, then via forwarding functions.
>
> That way existing uses of stream_socket continue to work as-is.
> Uses of stream templates would lose access to the underlying
> socket's I/O functions, as you want.
>
> Note there is still a way to circumvent the layering but it is
> now an explicit choice, e.g.:
>
> stream_socket inner(demuxer);
> buffered_stream<stream_socket&> outer(inner);
>
> Would anyone else care to comment on this modification?
>
I think that there should be NO portable way to get the underlying
core_socket from a stream_socket. In fact, while the inheritance holds
for BSD sockets (i.e posix sockets and winapi SOCKETS), it probably does
not make any sense for any other kind of transport. Generic code should
NOT assume that datagram sockets, acceptor sockets, stream sockets of a
given domain can be converted to the same type.
On the other hand there should definitely be a way to access the
underlying base type for domain/system specific code for example using
friend global functions, i.e.
core_socket& posix_get_core_socket(<derived socket type>&),
core_socket& winapi_get_core_socket(<derived socket type>&)
Code that uses them must understand that they are specific and not a
generic interface.
Comments?
gdp
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk