[system] remarks and feedback

Hi Beman, one thing I forgot in my last post about the system library: wouldn't boost/cstdlib.hpp fit nicely into it? PS: this thread's subject has been purposedly "generalized" so that, unless there are objections, we can group all our comments on the system library here. --Gennaro.

I'm thinking it might be helpful in the discussion for me to try to document in precise terms what asio would need from error_code and how it would be used. What's needed from error_code ============================= Testing for equality: Given error_code ec1(value1, category1); error_code ec2(value1, category1); error_code ec3(value2, category1); Then ec1 == ec2 evaluates to true ec1 == ec3 evaluates to false What asio will say ================== (For the sake of brevity I will only discuss a couple of error codes, but others will follow the same pattern.) There will be an error_code object: namespace boost { namespace asio { namespace error { extern error_code connection_reset; }}} On non-POSIX implementations, the initialisation of connection_reset is implementation-defined. On POSIX implementations, the initialisation of connection_reset shall be: error_code connection_reset(ECONNRESET, from_errno); such that both of the following expressions shall evaluate to true: connection_reset == error_code(ECONNRESET, from_errno) connection_reset.errno_value() == ECONNRESET In the following code, sock is a variable with the type boost::asio::ip::tcp::socket. char buf[128]; error_code ec; sock.receive(boost::asio::buffer(buf), ec); If an error occurs during the socket receive() such that the connection was reset by the peer (and this condition is reported to asio by a unique system error code), the following expression shall evaluate to true on all implementations (POSIX and non-POSIX): ec == boost::asio::error::connection_reset Furthermore, on POSIX implementations the following expressions shall evaluate to true: ec == error_code(ECONNRESET, from_errno) ec.errno_value() == ECONNRESET There will be an error_code object: namespace boost { namespace asio { namespace error { extern error_code name_not_found; }}} On non-POSIX implementations, the initialisation of name_not_found is implementation-defined. On POSIX implementations, the initialisation of name_not_found shall be: ??? // Needs error category support. From // the getaddrinfo error EAI_NONAME. In the following code, resolver is a variable with the type boost::asio::ip::tcp::resolver. boost::asio::ip::tcp::resolver::query query("foo", "bar"); error_code ec; resolver.resolve(query, ec); If an error occurs during name resolution such that the host is not found, the following expression shall evaluate to true on all implementations (POSIX and non-POSIX): ec == boost::asio::error::name_not_found Furthermore, on POSIX implementations the following expressions shall evaluate to true: ??? // Again, needs error category support. That's all I can think of for now. Cheers, Chris

Christopher Kohlhoff wrote:
ec == boost::asio::error::connection_reset
With this design, it is very likely that you (or your users) will also need bool operator<( error_code, error_code ); and size_t hash_value( error_code ); in order to create a map keyed on error_code that contains the asio predefined values.

"Peter Dimov" <pdimov@mmltd.net> wrote in message news:006901c69ac7$b2e35490$6407a8c0@pdimov2...
Christopher Kohlhoff wrote:
ec == boost::asio::error::connection_reset
With this design, it is very likely that you (or your users) will also need
bool operator<( error_code, error_code );
and
size_t hash_value( error_code );
in order to create a map keyed on error_code that contains the asio predefined values.
Yes. I'll add those functions. Thanks, --Beman

"Christopher Kohlhoff" <chris@kohlhoff.com> wrote in message news:20060628140024.38036.qmail@web32601.mail.mud.yahoo.com...
I'm thinking it might be helpful in the discussion for me to try to document in precise terms what asio would need from error_code and how it would be used.
What's needed from error_code =============================
Testing for equality:
Given error_code ec1(value1, category1); error_code ec2(value1, category1); error_code ec3(value2, category1); Then ec1 == ec2 evaluates to true ec1 == ec3 evaluates to false
Makes sense.
What asio will say ==================
(For the sake of brevity I will only discuss a couple of error codes, but others will follow the same pattern.)
There will be an error_code object:
namespace boost { namespace asio { namespace error { extern error_code connection_reset; }}}
Yes, but shouldn't that be: extern const error_code connection_reset; You don't want users to be able to change connection_reset to some other value.
On non-POSIX implementations, the initialisation of connection_reset is implementation-defined.
On POSIX implementations, the initialisation of connection_reset shall be:
error_code connection_reset(ECONNRESET, from_errno);
such that both of the following expressions shall evaluate to true:
connection_reset == error_code(ECONNRESET, from_errno) connection_reset.errno_value() == ECONNRESET
Yes.
... More examples
I think we are on track. I'll try to post a revised interface later today.
That's all I can think of for now.
Thanks for the examples. That really helps. --Beman
participants (4)
-
Beman Dawes
-
Christopher Kohlhoff
-
Gennaro Prota
-
Peter Dimov