Changeset 4dd8529 in mainline for uspace/lib/socket/include/net_err.h


Ignore:
Timestamp:
2010-04-06T11:39:41Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
24ab58b3
Parents:
11e543c
Message:

decode socket/network errors as human-readable descriptions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/socket/include/net_err.h

    r11e543c r4dd8529  
    2828
    2929/** @addtogroup net
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Common error processing codes and routines.
     34 * Common error processing codes and routines.
    3535 */
    3636
     
    4141
    4242#ifdef CONFIG_DEBUG
     43        #include <stdio.h>
     44        #include <strerror.h>
     45#endif
    4346
    44 #include <stdio.h>
     47/** An actual stored error code.
     48 *
     49 */
     50#define ERROR_CODE  error_check_return_value
     51
     52/** An error processing routines declaration.
     53 *
     54 * This has to be declared in the block where the error processing
     55 * is desired.
     56 *
     57 */
     58#define ERROR_DECLARE  int ERROR_CODE
     59
     60/** Store the value as an error code and checks if an error occurred.
     61 *
     62 * @param[in] value The value to be checked. May be a function call.
     63 * @return False if the value indicates success (EOK).
     64 * @return True otherwise.
     65 *
     66 */
     67#ifdef CONFIG_DEBUG
     68
     69#define ERROR_OCCURRED(value) \
     70        (((ERROR_CODE = (value)) != EOK) \
     71        && ({ \
     72                fprintf(stderr, "libsocket error at %s:%d (%s)\n", \
     73                __FILE__, __LINE__, str_error(ERROR_CODE)); \
     74                1; \
     75        }))
     76
     77#else
     78
     79#define ERROR_OCCURRED(value)  ((ERROR_CODE = (value)) != EOK)
    4580
    4681#endif
    4782
    48 /** An actual stored error code.
    49  */
    50 #define ERROR_CODE                                      error_check_return_value
    51 
    52 /** An error processing routines declaration.
    53  *  This has to be declared in the block where the error processing is desired.
    54  */
    55 #define ERROR_DECLARE                           int ERROR_CODE
    56 
    57 /** Stores the value as an error code and checks if an error occurred.
    58  *  @param[in] value The value to be checked. May be a function call.
    59  *  @returns FALSE if the value indicates success (EOK).
    60  *  @returns TRUE otherwise.
    61  */
    62 #ifdef CONFIG_DEBUG
    63 
    64 #define ERROR_OCCURRED(value)                                                                                           \
    65         (((ERROR_CODE = (value)) != EOK)                                                                                \
    66         && ({printf("error at %s:%d %d\n", __FILE__, __LINE__, ERROR_CODE); 1;}))
    67 
    68 #else
    69 
    70 #define ERROR_OCCURRED(value)           ((ERROR_CODE = (value)) != EOK)
    71 
    72 #endif
    73 
    74 /** Checks if an error occurred and immediately exits the actual function returning the error code.
    75  *  @param[in] value The value to be checked. May be a function call.
     83/** Error propagation
     84 *
     85 * Check if an error occurred and immediately exit the actual
     86 * function returning the error code.
     87 *
     88 * @param[in] value The value to be checked. May be a function call.
     89 *
    7690 */
    7791
    78 #define ERROR_PROPAGATE(value)  if(ERROR_OCCURRED(value)) return ERROR_CODE
     92#define ERROR_PROPAGATE(value) \
     93        if (ERROR_OCCURRED(value)) \
     94                return ERROR_CODE
    7995
    8096#endif
Note: See TracChangeset for help on using the changeset viewer.