- Feature Name: network errors handling
- Start Date: 2017-02-15
- RFC PR: (leave this empty)
- Pony Issue: (leave this empty)
Provide API for handling network errors.
Current interfaces, such as TCPListenNotify, TCPConnectionNotify
and UDPNotify do not provide any information about why some action
has failed. This makes it difficult to figure out software
configuration errors. Knowledge about nature of network failure is
essential for production software.
- Create a primivite union of possible network errors, similar to
FileErrNo, that maps a platform specific errno codes on these primitive values.
type SocketErrNo is
( SocketOK
| SocketError
| SocketInUse
| SocketConnRefused
| SocketNetUnreach
| SocketTimeout
)Where:
SocketOK- successSocketInUse- local address is already in useSocketConnRefused- no-one listening on the remote addressSocketNetUnreach- no routing to remote hostSocketTimeout- timeout while attempting connectionSocketError- other socket error not listed above
-
Add private
_errnofield ofSocketErrNotype intoTCPConnection,UDPSocketandTCPListener. On connection outcome, either success or failure,_errnomust be set using corresponding OS errno code fetched usingSO_ERRORsocket option -
Create publically available method
errnowhich returns_errno, for example:
fun errno(): SocketErrNo =>
"""
Returns the last error code set for this socket
"""
_errnoUpdate the doc strings for TCPConnectionNotify.connect_failed,
UDPNotify.not_listening and TCPListenNotify.not_listening
describing error fetching mechanism described in Design section.
Code example, showing usage of handling errors, is highly encouraged.
Add test case of making invalid connection, checking that errno is set uppon call to notifier.
Requires changes in libponyrt/lang/socket.c since actual value for
SO_ERROR is not exposed to pony level.
Extend notifiers API, so error code is provided uppon call to notifier. This approach looks not that smooth to integrate as proposed in Design section.
How proposed API conforms with RFC 23