Changeset ec1bdc8 in mainline for uspace/lib
- Timestamp:
- 2010-09-26T18:57:30Z (15 years ago)
- 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. - Location:
- uspace/lib
- Files:
-
- 8 added
- 10 deleted
- 17 edited
- 1 moved
-
c/Makefile (modified) (1 diff)
-
c/generic/adt/char_map.c (added)
-
c/generic/adt/dynamic_fifo.c (added)
-
c/generic/adt/measured_strings.c (added)
-
c/include/adt/char_map.h (added)
-
c/include/adt/dynamic_fifo.h (added)
-
c/include/adt/generic_char_map.h (added)
-
c/include/adt/generic_field.h (added)
-
c/include/adt/int_map.h (added)
-
c/include/adt/measured_strings.h (moved) (moved from uspace/lib/socket/include/net_err.h ) (1 diff)
-
c/include/err.h (modified) (2 diffs)
-
c/include/errno.h (modified) (1 diff)
-
net/adt/module_map.c (modified) (1 diff)
-
net/generic/packet_remote.c (modified) (1 diff)
-
net/il/ip_client.c (modified) (1 diff)
-
net/include/netif_local.h (modified) (1 diff)
-
net/netif/netif_local.c (modified) (1 diff)
-
net/tl/tl_common.c (modified) (2 diffs)
-
socket/Makefile (modified) (1 diff)
-
socket/adt/char_map.c (deleted)
-
socket/adt/dynamic_fifo.c (deleted)
-
socket/adt/measured_strings.c (deleted)
-
socket/generic/net_modules.c (modified) (2 diffs)
-
socket/generic/socket_client.c (modified) (1 diff)
-
socket/generic/socket_core.c (modified) (1 diff)
-
socket/include/adt/char_map.h (deleted)
-
socket/include/adt/dynamic_fifo.h (deleted)
-
socket/include/adt/generic_char_map.h (deleted)
-
socket/include/adt/generic_field.h (deleted)
-
socket/include/adt/int_map.h (deleted)
-
socket/include/adt/measured_strings.h (deleted)
-
socket/include/socket.h (modified) (1 diff)
-
socket/include/socket_errno.h (deleted)
-
socket/packet/packet.c (modified) (1 diff)
-
socket/packet/packet_client.c (modified) (4 diffs)
-
socket/packet/packet_server.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
r2a786f9 rec1bdc8 89 89 generic/adt/list.o \ 90 90 generic/adt/hash_table.o \ 91 generic/adt/dynamic_fifo.c \ 92 generic/adt/measured_strings.c \ 93 generic/adt/char_map.c \ 91 94 generic/time.c \ 92 95 generic/err.c \ -
uspace/lib/c/include/adt/measured_strings.h
r2a786f9 rec1bdc8 27 27 */ 28 28 29 /** @addtogroup net30 * @{29 /** @addtogroup libc 30 * @{ 31 31 */ 32 32 33 33 /** @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. 35 37 */ 36 38 37 #ifndef __NET_ERR_H__38 #define __NET_ERR_H__39 #ifndef LIBC_MEASURED_STRINGS_H_ 40 #define LIBC_MEASURED_STRINGS_H_ 39 41 40 #include < errno.h>42 #include <sys/types.h> 41 43 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 */ 47 typedef struct measured_string measured_string_t; 46 48 47 /** An actual stored error code. 49 /** Type definition of the character string with measured length pointer. 50 * @see measured_string 51 */ 52 typedef measured_string_t *measured_string_ref; 53 54 /** Character string with measured length. 48 55 * 56 * This structure has been designed for serialization of character strings 57 * between modules. 49 58 */ 50 #define ERROR_CODE error_check_return_value 59 struct measured_string { 60 /** Character string data. */ 61 char * value; 62 /** Character string length. */ 63 size_t length; 64 }; 51 65 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 66 extern measured_string_ref measured_string_create_bulk(const char *, size_t); 67 extern measured_string_ref measured_string_copy(measured_string_ref); 68 extern int measured_strings_receive(measured_string_ref *, char **, size_t); 69 extern int measured_strings_reply(const measured_string_ref, size_t); 70 extern int measured_strings_return(int, measured_string_ref *, char **, size_t); 71 extern int measured_strings_send(int, const measured_string_ref, size_t); 97 72 98 73 #endif -
uspace/lib/c/include/err.h
r2a786f9 rec1bdc8 36 36 #define LIBC_ERR_H_ 37 37 38 #include <stdio.h> 39 #include <errno.h> 40 41 #ifdef CONFIG_DEBUG 42 #include <str_error.h> 43 #endif 44 38 45 #define errx(status, fmt, ...) { \ 39 46 printf((fmt), ##__VA_ARGS__); \ … … 41 48 } 42 49 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 43 98 #endif 44 99 -
uspace/lib/c/include/errno.h
r2a786f9 rec1bdc8 56 56 #define EMLINK (-266) 57 57 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 58 94 #endif 59 95 -
uspace/lib/net/adt/module_map.c
r2a786f9 rec1bdc8 38 38 #include <task.h> 39 39 #include <unistd.h> 40 #include <err.h> 40 41 41 42 #include <ipc/services.h> 42 43 43 #include <net_err.h>44 44 #include <net_modules.h> 45 45 -
uspace/lib/net/generic/packet_remote.c
r2a786f9 rec1bdc8 38 38 #include <async.h> 39 39 #include <errno.h> 40 #include <err.h> 40 41 #include <ipc/ipc.h> 41 42 #include <sys/mman.h> 42 43 43 #include <net_err.h>44 44 #include <net_messages.h> 45 45 #include <packet/packet.h> -
uspace/lib/net/il/ip_client.c
r2a786f9 rec1bdc8 40 40 41 41 #include <ip_client.h> 42 #include <socket_errno.h>43 42 #include <packet/packet.h> 44 43 #include <packet/packet_client.h> -
uspace/lib/net/include/netif_local.h
r2a786f9 rec1bdc8 44 44 #include <ipc/ipc.h> 45 45 #include <ipc/services.h> 46 #include <err.h> 46 47 47 48 #include <adt/measured_strings.h> 48 #include <net_err.h>49 49 #include <net_device.h> 50 50 #include <packet/packet.h> -
uspace/lib/net/netif/netif_local.c
r2a786f9 rec1bdc8 42 42 #include <ipc/ipc.h> 43 43 #include <ipc/services.h> 44 45 #include <net_err.h> 44 #include <err.h> 45 46 46 #include <net_messages.h> 47 47 #include <net_modules.h> -
uspace/lib/net/tl/tl_common.c
r2a786f9 rec1bdc8 38 38 #include <async.h> 39 39 #include <ipc/services.h> 40 41 #include <net_err.h> 40 #include <errno.h> 41 #include <err.h> 42 42 43 #include <packet/packet.h> 43 44 #include <packet/packet_client.h> … … 51 52 #include <ip_remote.h> 52 53 #include <socket_codes.h> 53 #include <socket_errno.h>54 54 #include <ip_interface.h> 55 55 #include <tl_interface.h> -
uspace/lib/socket/Makefile
r2a786f9 rec1bdc8 42 42 packet/packet.c \ 43 43 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 48 45 49 46 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/socket/generic/net_modules.c
r2a786f9 rec1bdc8 37 37 #include <async.h> 38 38 #include <malloc.h> 39 #include <err.h> 39 40 40 41 #include <ipc/ipc.h> … … 43 44 #include <sys/time.h> 44 45 45 #include <net_err.h>46 46 #include <net_modules.h> 47 47 -
uspace/lib/socket/generic/socket_client.c
r2a786f9 rec1bdc8 42 42 #include <stdint.h> 43 43 #include <stdlib.h> 44 #include <errno.h> 45 #include <err.h> 44 46 45 47 #include <ipc/services.h> 46 48 47 #include <net_err.h>48 49 #include <net_modules.h> 49 50 #include <in.h> 50 51 #include <socket.h> 51 #include <socket_errno.h>52 52 #include <adt/dynamic_fifo.h> 53 53 #include <adt/int_map.h> -
uspace/lib/socket/generic/socket_core.c
r2a786f9 rec1bdc8 37 37 #include <stdint.h> 38 38 #include <stdlib.h> 39 40 #include <net_err.h> 39 #include <errno.h> 40 #include <err.h> 41 41 42 #include <in.h> 42 43 #include <inet.h> 43 44 #include <socket_codes.h> 44 #include <socket_errno.h>45 45 #include <adt/dynamic_fifo.h> 46 46 #include <adt/int_map.h> -
uspace/lib/socket/include/socket.h
r2a786f9 rec1bdc8 45 45 #include <inet.h> 46 46 #include <socket_codes.h> 47 #include < socket_errno.h>47 #include <errno.h> 48 48 49 49 /** @name Socket application programming interface -
uspace/lib/socket/packet/packet.c
r2a786f9 rec1bdc8 36 36 */ 37 37 38 #include <errno.h>39 38 #include <malloc.h> 40 39 #include <mem.h> 41 40 #include <fibril_synch.h> 42 41 #include <unistd.h> 42 #include <errno.h> 43 #include <err.h> 43 44 44 45 #include <sys/mman.h> 45 46 46 #include <net_err.h>47 47 #include <adt/generic_field.h> 48 48 #include <packet/packet.h> -
uspace/lib/socket/packet/packet_client.c
r2a786f9 rec1bdc8 46 46 #include <packet/packet_client.h> 47 47 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){ 48 int 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) 53 54 return ENOMEM; 54 } 55 55 56 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) 57 58 packet->data_end = packet->data_start + length; 58 } 59 59 60 return EOK; 60 61 } 61 62 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 } 63 void *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 66 71 packet->data_start -= length; 67 72 return (void *) packet + packet->data_start; 68 73 } 69 74 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 } 75 void *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 74 82 packet->data_end += length; 75 83 return (void *) packet + packet->data_end - length; 76 84 } 77 85 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)){ 86 int 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)) 83 92 return ENOMEM; 84 } 93 85 94 packet->data_start += prefix; 86 95 packet->data_end -= suffix; … … 88 97 } 89 98 90 packet_id_t packet_get_id(const packet_t packet){ 99 packet_id_t packet_get_id(const packet_t packet) 100 { 91 101 return packet_is_valid(packet) ? packet->packet_id : 0; 92 102 } 93 103 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){104 int 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) 99 109 return 0; 100 } 101 if(src){ 110 if (src) 102 111 *src = (void *) packet + packet->src_addr; 103 } 104 if(dest){ 112 if (dest) 105 113 *dest = (void *) packet + packet->dest_addr; 106 } 114 107 115 return packet->addr_len; 108 116 } 109 117 110 size_t packet_get_data_length(const packet_t packet){ 111 if(! packet_is_valid(packet)){ 118 size_t packet_get_data_length(const packet_t packet) 119 { 120 if (!packet_is_valid(packet)) 112 121 return 0; 113 } 122 114 123 return PACKET_DATA_LENGTH(packet); 115 124 } 116 125 117 void * packet_get_data(const packet_t packet){ 118 if(! packet_is_valid(packet)){ 119 return NULL; 120 } 126 void *packet_get_data(const packet_t packet) 127 { 128 if (!packet_is_valid(packet)) 129 return NULL; 130 121 131 return (void *) packet + packet->data_start; 122 132 } … … 160 170 } 161 171 162 packet_t packet_get_copy(int phone, packet_t packet){ 172 packet_t packet_get_copy(int phone, packet_t packet) 173 { 163 174 packet_t copy; 164 175 uint8_t * src = NULL; … … 166 177 size_t addrlen; 167 178 168 if (! packet_is_valid(packet)){169 return NULL; 170 } 179 if (!packet_is_valid(packet)) 180 return NULL; 181 171 182 // 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 176 189 // get addresses 177 190 addrlen = packet_get_addr(packet, &src, &dest); 178 191 // 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))) { 182 197 copy->order = packet->order; 183 198 copy->metric = packet->metric; 184 199 return copy; 185 } else{200 } else { 186 201 pq_release_local(phone, copy->packet_id); 187 202 return NULL; -
uspace/lib/socket/packet/packet_server.c
r2a786f9 rec1bdc8 39 39 #include <async.h> 40 40 #include <errno.h> 41 #include <err.h> 41 42 #include <fibril_synch.h> 42 43 #include <unistd.h> … … 45 46 #include <sys/mman.h> 46 47 47 #include <net_err.h>48 48 #include <net_messages.h> 49 49 #include <packet/packet.h>
Note:
See TracChangeset
for help on using the changeset viewer.
