[zeromq-dev] Handling errors from OpenPGM call pgm_recv() and friends
Steven McCoy
steven.mccoy at miru.hk
Tue Dec 22 03:15:15 CET 2009
2009/12/22 Martin Sustrik <sustrik at 250bpm.com>
> Hi Steven,
>
> I've modified the code in the following way:
>
> // Bind a transport to the specified network devices.
> if (!pgm_transport_bind (transport, &pgm_error)) {
> if (pgm_error->code == PGM_IF_ERROR_INVAL ||
> pgm_error->code == PGM_IF_ERROR_XDEV ||
> pgm_error->code == PGM_IF_ERROR_NODEV ||
> pgm_error->code == PGM_IF_ERROR_NOTUNIQ ||
> pgm_error->code == PGM_IF_ERROR_ADDRFAMILY ||
> pgm_error->code == PGM_IF_ERROR_FAMILY ||
> pgm_error->code == PGM_IF_ERROR_NODATA ||
> pgm_error->code == PGM_IF_ERROR_NONAME ||
> pgm_error->code == PGM_IF_ERROR_SERVICE) {
> g_error_free (pgm_error);
> errno = EINVAL;
> return -1;
> }
>
> zmq_assert (false);
> }
>
> The idea is that the problems caused by user are reported as EINVAL. If
> there'll be need for more fine grained errors we can then map OpenPGM errors
> to errnos, as required by concrete scenarios.
>
> The errors not caused by the user result in an assertion. If these occur in
> practice, we can either add the code to handle the error decently (say by
> restarting the transport) or return adequate errno.
>
> Does the code look right? I was not sure about the "domain" in the error.
>
>
The domains allow for separate namespaces for error codes, which means
PGM_IF_ERROR_INVAL has the same code value as PGM_TRANSPORT_ERROR_FAULT,
meaning you will want to change the code to something like this,
if (!pgm_transport_bind (transport, &pgm_error)) {
if (pgm_error->domain == PGM_IF_ERROR &&
(pgm_error->code == PGM_IF_ERROR_INVAL ||
pgm_error->code == PGM_IF_ERROR_XDEV ||
pgm_error->code == PGM_IF_ERROR_NODEV ||
pgm_error->code == PGM_IF_ERROR_NOTUNIQ ||
pgm_error->code == PGM_IF_ERROR_ADDRFAMILY ||
pgm_error->code == PGM_IF_ERROR_FAMILY ||
pgm_error->code == PGM_IF_ERROR_NODATA ||
pgm_error->code == PGM_IF_ERROR_NONAME ||
pgm_error->code == PGM_IF_ERROR_SERVICE)) {
g_error_free (pgm_error);
errno = EINVAL;
return -1;
}
zmq_assert (false);
}
--
Steve-o
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20091222/96f25bd1/attachment.htm>
More information about the zeromq-dev
mailing list