asio-tr2 icon indicating copy to clipboard operation
asio-tr2 copied to clipboard

Reconsider ip::address default constructor

Open chriskohlhoff opened this issue 10 years ago • 10 comments

The proposal currently specifies that a default constructed ip::address have is_ipv4() == false and is_ipv6() == false. Or to put it another way, the ip::address class can contain:

  • an IPv4 address; or
  • an IPv6 address; or
  • a Not-An-Address value

So right now the ip::address class can represent a value that is outside the domain of valid IP addresses. This is not the established practice in Asio and as I implement this I am finding that it might cause inconsistencies in the other types that use ip::address, like ip::basic_endpoint.

chriskohlhoff avatar Feb 15 '15 01:02 chriskohlhoff

So what are the options? Remove it or make it equal to a v4 address?

ja11sop avatar Feb 15 '15 01:02 ja11sop

So far I've got three options:

  • Option 1: Revert to asio behaviour, i.e. ip::address() == ip::address_v4()
  • Option 2: Keep current behaviour, fudge the endpoint and protocol classes (i.e. current wording might be ok)
  • Option 3: Keep current behaviour, change InternetProtocol requirements to add Protocol::unspecified()

chriskohlhoff avatar Feb 15 '15 01:02 chriskohlhoff

It seems that Option 1 has the advantage of being known to work well. The other options seem to open the door to possible side-effects yet to be well understood.

ja11sop avatar Feb 15 '15 01:02 ja11sop

  • Option 4: Make it an error (exception?) to construct an endpoint from a default-constructed ip::address

chriskohlhoff avatar Feb 15 '15 01:02 chriskohlhoff

Thinking about Option 4 I could see how allowing a 'not an address' state could lead to lots of validity checking in user code that takes an ip::address either pre-emptively or in response to a possible exception. Of course users should probably pass values and let them be dealt with by objects that care (like endpoint) but I can envisage many not doing that.

ja11sop avatar Feb 15 '15 01:02 ja11sop

MC to take up issue with Jeffrey

chriskohlhoff avatar Feb 27 '15 08:02 chriskohlhoff

Decision in Cologne meeting was to return to the existing experience of Asio. I.e. remove the 'not an address' state and default-construct as an IPv4 address.

chriskohlhoff avatar Mar 02 '15 07:03 chriskohlhoff

Applied in 61a9eed45cbd718373110d87d65bca90b8b34850.

chriskohlhoff avatar Apr 12 '15 11:04 chriskohlhoff

Pre-Lenexa Summary

[internet.address]

The original asio design of ip::address was that an address is either IPv4 or IPv6. A default constructed address is the IPv4 any address.

During SG4 discussion of the separate IP Address proposal, the design was changed to introduce a not-an-address value as the default. As described above, adding this out-of-domain value caused some consistency problems when incorporated into the wider Asio-based proposal, e.g. in the basic_endpoint default constructor. It also significantly complicated the specification of some functions, like the ip::address relational operators.

When we discussed about this in Cologne, we decided that we should return to Asio's original behaviour. LEWG needs to confirm this decision.

The change was included in revision 5. An implementation can be found on the master branch of Asio's GitHub repository.

chriskohlhoff avatar May 05 '15 08:05 chriskohlhoff

LEWG reviewed this, unanimous consent to making IPv4 the default state

jwakely avatar May 06 '15 21:05 jwakely