Changeset ec1bdc8 in mainline for uspace/lib


Ignore:
Timestamp:
2010-09-26T18:57:30Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3fe57ea7
Parents:
2a786f9 (diff), 70ce016 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/net.

Location:
uspace/lib
Files:
8 added
10 deleted
17 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    r2a786f9 rec1bdc8  
    8989        generic/adt/list.o \
    9090        generic/adt/hash_table.o \
     91        generic/adt/dynamic_fifo.c \
     92        generic/adt/measured_strings.c \
     93        generic/adt/char_map.c \
    9194        generic/time.c \
    9295        generic/err.c \
  • uspace/lib/c/include/adt/measured_strings.h

    r2a786f9 rec1bdc8  
    2727 */
    2828
    29 /** @addtogroup net
    30  * @{
     29/** @addtogroup libc
     30 *  @{
    3131 */
    3232
    3333/** @file
    34  * Common error processing codes and routines.
     34 * Character string with measured length.
     35 * The structure has been designed for serialization of character strings
     36 * between modules.
    3537 */
    3638
    37 #ifndef __NET_ERR_H__
    38 #define __NET_ERR_H__
     39#ifndef LIBC_MEASURED_STRINGS_H_
     40#define LIBC_MEASURED_STRINGS_H_
    3941
    40 #include <errno.h>
     42#include <sys/types.h>
    4143
    42 #ifdef CONFIG_DEBUG
    43         #include <stdio.h>
    44         #include <str_error.h>
    45 #endif
     44/** Type definition of the character string with measured length.
     45 *  @see measured_string
     46 */
     47typedef struct measured_string measured_string_t;
    4648
    47 /** An actual stored error code.
     49/** Type definition of the character string with measured length pointer.
     50 *  @see measured_string
     51 */
     52typedef measured_string_t *measured_string_ref;
     53
     54/** Character string with measured length.
    4855 *
     56 * This structure has been designed for serialization of character strings
     57 * between modules.
    4958 */
    50 #define ERROR_CODE  error_check_return_value
     59struct measured_string {
     60        /** Character string data. */
     61        char * value;
     62        /** Character string length. */
     63        size_t length;
     64};
    5165
    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)
    80 
    81 #endif
    82 
    83 #define ERROR_NONE(value)       !ERROR_OCCURRED((value))
    84 
    85 /** Error propagation
    86  *
    87  * Check if an error occurred and immediately exit the actual
    88  * function returning the error code.
    89  *
    90  * @param[in] value The value to be checked. May be a function call.
    91  *
    92  */
    93 
    94 #define ERROR_PROPAGATE(value) \
    95         if (ERROR_OCCURRED(value)) \
    96                 return ERROR_CODE
     66extern measured_string_ref measured_string_create_bulk(const char *, size_t);
     67extern measured_string_ref measured_string_copy(measured_string_ref);
     68extern int measured_strings_receive(measured_string_ref *, char **, size_t);
     69extern int measured_strings_reply(const measured_string_ref, size_t);
     70extern int measured_strings_return(int, measured_string_ref *, char **, size_t);
     71extern int measured_strings_send(int, const measured_string_ref, size_t);
    9772
    9873#endif
  • uspace/lib/c/include/err.h

    r2a786f9 rec1bdc8  
    3636#define LIBC_ERR_H_
    3737
     38#include <stdio.h>
     39#include <errno.h>
     40
     41#ifdef CONFIG_DEBUG
     42#include <str_error.h>
     43#endif
     44
    3845#define errx(status, fmt, ...) { \
    3946        printf((fmt), ##__VA_ARGS__); \
     
    4148}
    4249
     50
     51/** An actual stored error code.  */
     52#define ERROR_CODE  error_check_return_value
     53
     54/** An error processing routines declaration.
     55 *
     56 * This has to be declared in the block where the error processing
     57 * is desired.
     58 */
     59#define ERROR_DECLARE  int ERROR_CODE
     60
     61/** Store the value as an error code and checks if an error occurred.
     62 *
     63 * @param[in] value     The value to be checked. May be a function call.
     64 * @return              False if the value indicates success (EOK).
     65 * @return              True otherwise.
     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)
     80
     81#endif
     82
     83#define ERROR_NONE(value)       !ERROR_OCCURRED((value))
     84
     85/** Error propagation
     86 *
     87 * Check if an error occurred and immediately exit the actual
     88 * function returning the error code.
     89 *
     90 * @param[in] value     The value to be checked. May be a function call.
     91 *
     92 */
     93
     94#define ERROR_PROPAGATE(value) \
     95        if (ERROR_OCCURRED(value)) \
     96                return ERROR_CODE
     97
    4398#endif
    4499
  • uspace/lib/c/include/errno.h

    r2a786f9 rec1bdc8  
    5656#define EMLINK        (-266)
    5757
     58/** An API function is called while another blocking function is in progress. */
     59#define EINPROGRESS     (-10036)
     60
     61/** The socket identifier is not valid. */
     62#define ENOTSOCK        (-10038)
     63
     64/** The destination address required. */
     65#define EDESTADDRREQ    (-10039)
     66
     67/** Protocol is not supported.  */
     68#define EPROTONOSUPPORT (-10043)
     69
     70/** Socket type is not supported. */
     71#define ESOCKTNOSUPPORT (-10044)
     72
     73/** Protocol family is not supported. */
     74#define EPFNOSUPPORT    (-10046)
     75
     76/** Address family is not supported. */
     77#define EAFNOSUPPORT    (-10047)
     78
     79/** Address is already in use. */
     80#define EADDRINUSE      (-10048)
     81
     82/** The socket is not connected or bound. */
     83#define ENOTCONN        (-10057)
     84
     85/** The requested operation was not performed.
     86 *  Try again later.
     87 */
     88#define TRY_AGAIN       (-11002)
     89
     90/** No data.
     91 */
     92#define NO_DATA         (-11004)
     93
    5894#endif
    5995
  • uspace/lib/net/adt/module_map.c

    r2a786f9 rec1bdc8  
    3838#include <task.h>
    3939#include <unistd.h>
     40#include <err.h>
    4041
    4142#include <ipc/services.h>
    4243
    43 #include <net_err.h>
    4444#include <net_modules.h>
    4545
  • uspace/lib/net/generic/packet_remote.c

    r2a786f9 rec1bdc8  
    3838#include <async.h>
    3939#include <errno.h>
     40#include <err.h>
    4041#include <ipc/ipc.h>
    4142#include <sys/mman.h>
    4243
    43 #include <net_err.h>
    4444#include <net_messages.h>
    4545#include <packet/packet.h>
  • uspace/lib/net/il/ip_client.c

    r2a786f9 rec1bdc8  
    4040
    4141#include <ip_client.h>
    42 #include <socket_errno.h>
    4342#include <packet/packet.h>
    4443#include <packet/packet_client.h>
  • uspace/lib/net/include/netif_local.h

    r2a786f9 rec1bdc8  
    4444#include <ipc/ipc.h>
    4545#include <ipc/services.h>
     46#include <err.h>
    4647
    4748#include <adt/measured_strings.h>
    48 #include <net_err.h>
    4949#include <net_device.h>
    5050#include <packet/packet.h>
  • uspace/lib/net/netif/netif_local.c

    r2a786f9 rec1bdc8  
    4242#include <ipc/ipc.h>
    4343#include <ipc/services.h>
    44 
    45 #include <net_err.h>
     44#include <err.h>
     45
    4646#include <net_messages.h>
    4747#include <net_modules.h>
  • uspace/lib/net/tl/tl_common.c

    r2a786f9 rec1bdc8  
    3838#include <async.h>
    3939#include <ipc/services.h>
    40 
    41 #include <net_err.h>
     40#include <errno.h>
     41#include <err.h>
     42
    4243#include <packet/packet.h>
    4344#include <packet/packet_client.h>
     
    5152#include <ip_remote.h>
    5253#include <socket_codes.h>
    53 #include <socket_errno.h>
    5454#include <ip_interface.h>
    5555#include <tl_interface.h>
  • uspace/lib/socket/Makefile

    r2a786f9 rec1bdc8  
    4242        packet/packet.c \
    4343        packet/packet_client.c \
    44         packet/packet_server.c \
    45         adt/dynamic_fifo.c \
    46         adt/measured_strings.c \
    47         adt/char_map.c
     44        packet/packet_server.c
    4845
    4946include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/socket/generic/net_modules.c

    r2a786f9 rec1bdc8  
    3737#include <async.h>
    3838#include <malloc.h>
     39#include <err.h>
    3940
    4041#include <ipc/ipc.h>
     
    4344#include <sys/time.h>
    4445
    45 #include <net_err.h>
    4646#include <net_modules.h>
    4747
  • uspace/lib/socket/generic/socket_client.c

    r2a786f9 rec1bdc8  
    4242#include <stdint.h>
    4343#include <stdlib.h>
     44#include <errno.h>
     45#include <err.h>
    4446
    4547#include <ipc/services.h>
    4648
    47 #include <net_err.h>
    4849#include <net_modules.h>
    4950#include <in.h>
    5051#include <socket.h>
    51 #include <socket_errno.h>
    5252#include <adt/dynamic_fifo.h>
    5353#include <adt/int_map.h>
  • uspace/lib/socket/generic/socket_core.c

    r2a786f9 rec1bdc8  
    3737#include <stdint.h>
    3838#include <stdlib.h>
    39 
    40 #include <net_err.h>
     39#include <errno.h>
     40#include <err.h>
     41
    4142#include <in.h>
    4243#include <inet.h>
    4344#include <socket_codes.h>
    44 #include <socket_errno.h>
    4545#include <adt/dynamic_fifo.h>
    4646#include <adt/int_map.h>
  • uspace/lib/socket/include/socket.h

    r2a786f9 rec1bdc8  
    4545#include <inet.h>
    4646#include <socket_codes.h>
    47 #include <socket_errno.h>
     47#include <errno.h>
    4848
    4949/** @name Socket application programming interface
  • uspace/lib/socket/packet/packet.c

    r2a786f9 rec1bdc8  
    3636 */
    3737
    38 #include <errno.h>
    3938#include <malloc.h>
    4039#include <mem.h>
    4140#include <fibril_synch.h>
    4241#include <unistd.h>
     42#include <errno.h>
     43#include <err.h>
    4344
    4445#include <sys/mman.h>
    4546
    46 #include <net_err.h>
    4747#include <adt/generic_field.h>
    4848#include <packet/packet.h>
  • uspace/lib/socket/packet/packet_client.c

    r2a786f9 rec1bdc8  
    4646#include <packet/packet_client.h>
    4747
    48 int packet_copy_data(packet_t packet, const void * data, size_t length){
    49         if(! packet_is_valid(packet)){
    50                 return EINVAL;
    51         }
    52         if(packet->data_start + length >= packet->length){
     48int packet_copy_data(packet_t packet, const void * data, size_t length)
     49{
     50        if (!packet_is_valid(packet))
     51                return EINVAL;
     52
     53        if (packet->data_start + length >= packet->length)
    5354                return ENOMEM;
    54         }
     55
    5556        memcpy((void *) packet + packet->data_start, data, length);
    56         if(packet->data_start + length > packet->data_end){
     57        if (packet->data_start + length > packet->data_end)
    5758                packet->data_end = packet->data_start + length;
    58         }
     59
    5960        return EOK;
    6061}
    6162
    62 void * packet_prefix(packet_t packet, size_t length){
    63         if((! packet_is_valid(packet)) || (packet->data_start - sizeof(struct packet) - 2 * (packet->dest_addr - packet->src_addr) < length)){
    64                 return NULL;
    65         }
     63void *packet_prefix(packet_t packet, size_t length)
     64{
     65        if ((!packet_is_valid(packet)) ||
     66            (packet->data_start - sizeof(struct packet) -
     67            2 * (packet->dest_addr - packet->src_addr) < length)) {
     68                return NULL;
     69        }
     70
    6671        packet->data_start -= length;
    6772        return (void *) packet + packet->data_start;
    6873}
    6974
    70 void * packet_suffix(packet_t packet, size_t length){
    71         if((! packet_is_valid(packet)) || (packet->data_end + length >= packet->length)){
    72                 return NULL;
    73         }
     75void *packet_suffix(packet_t packet, size_t length)
     76{
     77        if ((!packet_is_valid(packet)) ||
     78            (packet->data_end + length >= packet->length)) {
     79                return NULL;
     80        }
     81
    7482        packet->data_end += length;
    7583        return (void *) packet + packet->data_end - length;
    7684}
    7785
    78 int packet_trim(packet_t packet, size_t prefix, size_t suffix){
    79         if(! packet_is_valid(packet)){
    80                 return EINVAL;
    81         }
    82         if(prefix + suffix > PACKET_DATA_LENGTH(packet)){
     86int packet_trim(packet_t packet, size_t prefix, size_t suffix)
     87{
     88        if (!packet_is_valid(packet))
     89                return EINVAL;
     90
     91        if (prefix + suffix > PACKET_DATA_LENGTH(packet))
    8392                return ENOMEM;
    84         }
     93
    8594        packet->data_start += prefix;
    8695        packet->data_end -= suffix;
     
    8897}
    8998
    90 packet_id_t packet_get_id(const packet_t packet){
     99packet_id_t packet_get_id(const packet_t packet)
     100{
    91101        return packet_is_valid(packet) ? packet->packet_id : 0;
    92102}
    93103
    94 int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest){
    95         if(! packet_is_valid(packet)){
    96                 return EINVAL;
    97         }
    98         if(! packet->addr_len){
     104int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest)
     105{
     106        if (!packet_is_valid(packet))
     107                return EINVAL;
     108        if (!packet->addr_len)
    99109                return 0;
    100         }
    101         if(src){
     110        if (src)
    102111                *src = (void *) packet + packet->src_addr;
    103         }
    104         if(dest){
     112        if (dest)
    105113                *dest = (void *) packet + packet->dest_addr;
    106         }
     114
    107115        return packet->addr_len;
    108116}
    109117
    110 size_t packet_get_data_length(const packet_t packet){
    111         if(! packet_is_valid(packet)){
     118size_t packet_get_data_length(const packet_t packet)
     119{
     120        if (!packet_is_valid(packet))
    112121                return 0;
    113         }
     122
    114123        return PACKET_DATA_LENGTH(packet);
    115124}
    116125
    117 void * packet_get_data(const packet_t packet){
    118         if(! packet_is_valid(packet)){
    119                 return NULL;
    120         }
     126void *packet_get_data(const packet_t packet)
     127{
     128        if (!packet_is_valid(packet))
     129                return NULL;
     130
    121131        return (void *) packet + packet->data_start;
    122132}
     
    160170}
    161171
    162 packet_t packet_get_copy(int phone, packet_t packet){
     172packet_t packet_get_copy(int phone, packet_t packet)
     173{
    163174        packet_t copy;
    164175        uint8_t * src = NULL;
     
    166177        size_t addrlen;
    167178
    168         if(! packet_is_valid(packet)){
    169                 return NULL;
    170         }
     179        if (!packet_is_valid(packet))
     180                return NULL;
     181
    171182        // get a new packet
    172         copy = packet_get_4_local(phone, PACKET_DATA_LENGTH(packet), PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix, PACKET_MIN_SUFFIX(packet));
    173         if(! copy){
    174                 return NULL;
    175         }
     183        copy = packet_get_4_local(phone, PACKET_DATA_LENGTH(packet),
     184            PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix,
     185            PACKET_MIN_SUFFIX(packet));
     186        if (!copy)
     187                return NULL;
     188
    176189        // get addresses
    177190        addrlen = packet_get_addr(packet, &src, &dest);
    178191        // copy data
    179         if((packet_copy_data(copy, packet_get_data(packet), PACKET_DATA_LENGTH(packet)) == EOK)
    180         // copy addresses if present
    181                 && ((addrlen <= 0) || (packet_set_addr(copy, src, dest, addrlen) == EOK))){
     192        if ((packet_copy_data(copy, packet_get_data(packet),
     193            PACKET_DATA_LENGTH(packet)) == EOK) &&
     194            // copy addresses if present
     195            ((addrlen <= 0) ||
     196            (packet_set_addr(copy, src, dest, addrlen) == EOK))) {
    182197                copy->order = packet->order;
    183198                copy->metric = packet->metric;
    184199                return copy;
    185         }else{
     200        } else {
    186201                pq_release_local(phone, copy->packet_id);
    187202                return NULL;
  • uspace/lib/socket/packet/packet_server.c

    r2a786f9 rec1bdc8  
    3939#include <async.h>
    4040#include <errno.h>
     41#include <err.h>
    4142#include <fibril_synch.h>
    4243#include <unistd.h>
     
    4546#include <sys/mman.h>
    4647
    47 #include <net_err.h>
    4848#include <net_messages.h>
    4949#include <packet/packet.h>
Note: See TracChangeset for help on using the changeset viewer.