BOOST WIKI | BoostSocket | RecentChanges | Preferences | Page List | Links List

PlatformSocket Concept

Anthony Liguori's comments below have been reflected in the code (see boost/socket/impl/default_socket_impl.hpp in sandbox). There is now a Socket Implementation template parameter to the socket_base class. This page needs changing to reflect this...

Platform Socket Type

Provide a platform independent typedef for the platform dependent socket type

Valid socket check


Anthony Liguori: 11/23/2002

I think there may be a fundamental flaw in a two level approach. That is the library appears to be heading towards bit-level interoperability with C socket libraries. I am a much bigger fan of convertable compatibility though and there is a precedence for this approach in the standard (std::string). For instance, perhaps something like:

namespace boost {

  namespace socket {
    namespace platform {
      struct Winsock2 {
        typedef SOCKET socket_type;
        socket_type s;
      struct Berkley {
        typedef int socket_type;
        socket_type s;
  struct <typename Platform=Berkley> // This could be determined rather easily at compile time
  struct socket {
     Platform::socket_type c_sock() {
     return impl.s;
    Platform impl;

boost::socket s;


send(s.c_sock(), ...);

Of course, this is just an idea. The nice thing about an approach like this is that we don't lose the power of strong typing that C++ offers over C. I shudder to think that boost would provide a type that is merely a typedef to an int ;-)

I'd also like to speak to the moving of platform-dependent code to a policy. This is nice for a few reasons:

1) For platform that have multiple socket interfaces, a user can choose which one to use.

2) We can formally specify the requirements of a socket policy and provide reference implementations for common platforms. Additional platforms could be supported without modification to the actual library.

3) Features that are platform specific (i.e. asyncronous host name resolution) could be implemented using incomplete instantiation (see the policy chapter in Modern C++ Design). This way, we could provide standard interfaces for features that don't exist on all platforms and provide compile-time checking to determine if a particular platform supports the feature.

BOOST WIKI | BoostSocket | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited December 18, 2004 12:27 pm (diff)
Disclaimer: This site not officially maintained by Boost Developers