api: uv_link_errno

This commit is contained in:
Fedor Indutny 2016-06-04 19:25:26 -04:00
parent 79d44e403c
commit 4916c3ba7e
3 changed files with 39 additions and 8 deletions

View File

@ -118,6 +118,15 @@ Invoke `shutdown` from the link's [`uv_link_methods_t`][]. Acts similarly to
`uv_shutdown()`. `cb(uv_link_t* link, int status, void* arg)` is invoked on
completion.
### int uv_link_errno(...)
* `uv_link_t** link`
* `int err` - error code, previously either returned the one of the
`uv_link...` methods or passed as a negative `nread` to `link->read_cb`
Unprefix internal error code and set the `link` pointer to the link that
have emitted that error.
### const char* uv_link_strerror(...)
* `uv_link_t* link`

View File

@ -125,6 +125,7 @@ static int uv_link_shutdown(uv_link_t* link, uv_link_shutdown_cb cb,
return uv_link_propagate_shutdown(link, link, cb, arg);
}
int uv_link_errno(uv_link_t** link, int err);
const char* uv_link_strerror(uv_link_t* link, int err);
/* Link Source */

View File

@ -221,21 +221,42 @@ int uv_link_unchain(uv_link_t* from, uv_link_t* to) {
}
const char* uv_link_strerror(uv_link_t* link, int err) {
int uv_link_errno(uv_link_t** link, int err) {
unsigned int prefix;
int local_err;
uv_link_t* p;
if (err >= UV_ERRNO_MAX) {
*link = NULL;
return err;
}
prefix = (-err) & kErrorPrefixMask;
local_err = -((-err) & kErrorValueMask);
for (p = *link; p != NULL; p = p->parent) {
if (prefix == p->err_prefix) {
*link = p;
return local_err;
}
}
*link = NULL;
return err;
}
const char* uv_link_strerror(uv_link_t* link, int err) {
int local_err;
if (err >= UV_ERRNO_MAX)
return uv_strerror(err);
prefix = (-err) & kErrorPrefixMask;
local_err = -((-err) & kErrorValueMask);
local_err = uv_link_errno(&link, err);
if (link == NULL)
return NULL;
for (; link != NULL; link = link->parent)
if (prefix == link->err_prefix)
return link->methods->strerror(link, local_err);
return NULL;
return link->methods->strerror(link, local_err);
}