Alan Conway wrote:
Here's a 3rd option:

class ConnectionPolicy {}; // Abstract base for connection policies.

class TcpConnectionPolicy {
  bool TCP_NODELAY;
  .. etc whatever we want to expose
}

class Connection {
 void applyPolicy(ConnetionPolicy&)
}

  TcpConnectionPolicy p;
  p.TCP_NODELAY = true;
  myConnection.applyPolicy(p);

The semantics here are that IF myConnection is indeed a TCP connection, the policy will be applied, if not, it will be ignored.

This supports the case where the users _knows_ they are dealing with TCP and _knows_ the TCP specific options they want. However the code remains portable and valid if it is someday run on a non TCP connection - the TCP policy is simply ignored.

We could extend this notion to provide generic policy options on policy base classes, or even to categorize transports into families with common options. I don't think we're there yet, but for now it's a good solution to setting TCP options in a portable way.

+1, I like that approach.

Reply via email to