Subject: Re: [boost] Boost.Asio asio::basic_socket_acceptor
From: Dmitry Goncharov (dgoncharov_at_[hidden])
Date: 2009-03-13 04:55:05


Joshua Pedrick wrote:
> I'm trying to write an application that can simply switch between
> using local stream sockets and tcp stream sockets. I successfully
> implemented this behavior with BSD sockets in Linux, but
> it seems the class hierarchy in boost::asio makes this behavior
> awkward, since asio::basic_socket_acceptor template requires a
> protocol type, but there is so base class for protocols. I'm wondering
> if there is a reason for this or if it could possibly be changed?
>
> Basically, I have a client/server library for distributed processing,
> which in some cases, I wish to run using local sockets and other times
> run using TCP sockets. I was hoping Boost Asio could make the solution
> a little more elegant/clean, but at the moment I can't find an elegant
> manner to do this.
>
> I'd be glad to do all the work for this, provided some guidance, but I
> basically don't want to build my application on a custom version of
> boost::asio, which won't improve with the main version. So if this
> can't be changed, I just won't use asio, but if it can, I'll go ahead
> and take the time to implement the changes
>
>

As a workaround you could write your custom protocol struct which
dispatches to either tcp or stream_protocol at runtime.
Something like
struct tcp_or_local
{
    int family() const
   {
          return tcp ? tcp().family() : stream_protocol().family;
   }
    bool tcp;
}

This is quite a limitation. Since the author is not responding does that
mean the library is going to stay as it is?

BR, Dmitry