Changeset a676574 in mainline for uspace/lib/c/generic
- Timestamp:
- 2011-01-09T12:18:00Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 54de5ebd
- Parents:
- a3eeef45 (diff), 9d12059 (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/c/generic
- Files:
-
- 1 added
- 1 deleted
- 17 edited
-
adt/char_map.c (modified) (6 diffs)
-
adt/measured_strings.c (modified) (6 diffs)
-
async.c (modified) (1 diff)
-
async_rel.c (deleted)
-
async_sess.c (added)
-
device/hw_res.c (modified) (1 diff)
-
devman.c (modified) (4 diffs)
-
devmap.c (modified) (1 diff)
-
fibril.c (modified) (1 diff)
-
fibril_synch.c (modified) (6 diffs)
-
io/vprintf.c (modified) (2 diffs)
-
libc.c (modified) (2 diffs)
-
mem.c (modified) (1 diff)
-
net/icmp_api.c (modified) (1 diff)
-
net/inet.c (modified) (6 diffs)
-
net/modules.c (modified) (6 diffs)
-
net/packet.c (modified) (1 diff)
-
net/socket_client.c (modified) (49 diffs)
-
task.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/char_map.c
ra3eeef45 ra676574 65 65 */ 66 66 static int 67 char_map_add_item(char_map_t *map, const char*identifier, size_t length,67 char_map_add_item(char_map_t *map, const uint8_t *identifier, size_t length, 68 68 const int value) 69 69 { … … 139 139 */ 140 140 int 141 char_map_add(char_map_t *map, const char*identifier, size_t length,141 char_map_add(char_map_t *map, const uint8_t *identifier, size_t length, 142 142 const int value) 143 143 { … … 200 200 */ 201 201 static char_map_t * 202 char_map_find_node(const char_map_t *map, const char*identifier,202 char_map_find_node(const char_map_t *map, const uint8_t *identifier, 203 203 size_t length) 204 204 { … … 241 241 * @return CHAR_MAP_NULL if the key is not assigned a value. 242 242 */ 243 int char_map_exclude(char_map_t *map, const char*identifier, size_t length)243 int char_map_exclude(char_map_t *map, const uint8_t *identifier, size_t length) 244 244 { 245 245 char_map_t *node; … … 269 269 * @return CHAR_MAP_NULL if the key is not assigned a value. 270 270 */ 271 int char_map_find(const char_map_t *map, const char*identifier, size_t length)271 int char_map_find(const char_map_t *map, const uint8_t *identifier, size_t length) 272 272 { 273 273 char_map_t *node; … … 329 329 */ 330 330 int 331 char_map_update(char_map_t *map, const char*identifier, const size_t length,331 char_map_update(char_map_t *map, const uint8_t *identifier, const size_t length, 332 332 const int value) 333 333 { -
uspace/lib/c/generic/adt/measured_strings.c
ra3eeef45 ra676574 59 59 */ 60 60 measured_string_t * 61 measured_string_create_bulk(const char*string, size_t length)61 measured_string_create_bulk(const uint8_t *string, size_t length) 62 62 { 63 63 measured_string_t *new; … … 68 68 } 69 69 new = (measured_string_t *) malloc(sizeof(measured_string_t) + 70 (sizeof( char) * (length + 1)));70 (sizeof(uint8_t) * (length + 1))); 71 71 if (!new) 72 72 return NULL; 73 73 74 74 new->length = length; 75 new->value = (( char*) new) + sizeof(measured_string_t);75 new->value = ((uint8_t *) new) + sizeof(measured_string_t); 76 76 // append terminating zero explicitly - to be safe 77 77 memcpy(new->value, string, new->length); … … 97 97 new = (measured_string_t *) malloc(sizeof(measured_string_t)); 98 98 if (new) { 99 new->value = ( char*) malloc(source->length + 1);99 new->value = (uint8_t *) malloc(source->length + 1); 100 100 if (new->value) { 101 101 new->length = source->length; … … 131 131 */ 132 132 int 133 measured_strings_receive(measured_string_t **strings, char**data,133 measured_strings_receive(measured_string_t **strings, uint8_t **data, 134 134 size_t count) 135 135 { … … 137 137 size_t index; 138 138 size_t length; 139 char*next;139 uint8_t *next; 140 140 ipc_callid_t callid; 141 141 int rc; … … 311 311 */ 312 312 int 313 measured_strings_return(int phone, measured_string_t **strings, char**data,313 measured_strings_return(int phone, measured_string_t **strings, uint8_t **data, 314 314 size_t count) 315 315 { 316 316 size_t *lengths; 317 317 size_t index; 318 char*next;318 uint8_t *next; 319 319 int rc; 320 320 -
uspace/lib/c/generic/async.c
ra3eeef45 ra676574 749 749 return ENOMEM; 750 750 } 751 752 _async_sess_init(); 751 753 752 754 return 0; -
uspace/lib/c/generic/device/hw_res.c
ra3eeef45 ra676574 38 38 #include <malloc.h> 39 39 40 boolget_hw_resources(int dev_phone, hw_resource_list_t *hw_resources)40 int get_hw_resources(int dev_phone, hw_resource_list_t *hw_resources) 41 41 { 42 42 sysarg_t count = 0; 43 43 int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), GET_RESOURCE_LIST, &count); 44 44 hw_resources->count = count; 45 if (EOK != rc) { 46 return false; 47 } 45 if (rc != EOK) 46 return rc; 48 47 49 48 size_t size = count * sizeof(hw_resource_t); 50 49 hw_resources->resources = (hw_resource_t *)malloc(size); 51 if (NULL == hw_resources->resources) { 52 return false; 53 } 50 if (!hw_resources->resources) 51 return ENOMEM; 54 52 55 53 rc = async_data_read_start(dev_phone, hw_resources->resources, size); 56 if ( EOK != rc) {54 if (rc != EOK) { 57 55 free(hw_resources->resources); 58 56 hw_resources->resources = NULL; 59 return false;57 return rc; 60 58 } 61 59 62 return true;60 return EOK; 63 61 } 64 62 -
uspace/lib/c/generic/devman.c
ra3eeef45 ra676574 58 58 59 59 if (flags & IPC_FLAG_BLOCKING) 60 devman_phone_driver = ipc_connect_me_to_blocking(PHONE_NS,61 SERVICE_DEVMAN, DEVMAN_DRIVER, 0);60 devman_phone_driver = async_connect_me_to_blocking( 61 PHONE_NS, SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 62 62 else 63 devman_phone_driver = ipc_connect_me_to(PHONE_NS,63 devman_phone_driver = async_connect_me_to(PHONE_NS, 64 64 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 65 65 … … 70 70 71 71 if (flags & IPC_FLAG_BLOCKING) 72 devman_phone_client = ipc_connect_me_to_blocking(PHONE_NS,73 SERVICE_DEVMAN, DEVMAN_CLIENT, 0);72 devman_phone_client = async_connect_me_to_blocking( 73 PHONE_NS, SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 74 74 else 75 devman_phone_client = ipc_connect_me_to(PHONE_NS,75 devman_phone_client = async_connect_me_to(PHONE_NS, 76 76 SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 77 77 … … 230 230 231 231 if (flags & IPC_FLAG_BLOCKING) { 232 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,232 phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN, 233 233 DEVMAN_CONNECT_TO_DEVICE, handle); 234 234 } else { 235 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,235 phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN, 236 236 DEVMAN_CONNECT_TO_DEVICE, handle); 237 237 } … … 245 245 246 246 if (flags & IPC_FLAG_BLOCKING) { 247 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,247 phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN, 248 248 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle); 249 249 } else { 250 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,250 phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN, 251 251 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle); 252 252 } -
uspace/lib/c/generic/devmap.c
ra3eeef45 ra676574 279 279 280 280 if (flags & IPC_FLAG_BLOCKING) { 281 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP,281 phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, 282 282 DEVMAP_CONNECT_TO_DEVICE, handle); 283 283 } else { 284 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP,284 phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAP, 285 285 DEVMAP_CONNECT_TO_DEVICE, handle); 286 286 } -
uspace/lib/c/generic/fibril.c
ra3eeef45 ra676574 361 361 } 362 362 363 int fibril_get_sercount(void) 364 { 365 return serialization_count; 366 } 367 363 368 /** @} 364 369 */ -
uspace/lib/c/generic/fibril_synch.c
ra3eeef45 ra676574 139 139 static void _fibril_mutex_unlock_unsafe(fibril_mutex_t *fm) 140 140 { 141 assert(fm->counter <= 0);142 141 if (fm->counter++ < 0) { 143 142 link_t *tmp; … … 165 164 void fibril_mutex_unlock(fibril_mutex_t *fm) 166 165 { 166 assert(fibril_mutex_is_locked(fm)); 167 167 futex_down(&async_futex); 168 168 _fibril_mutex_unlock_unsafe(fm); 169 169 futex_up(&async_futex); 170 } 171 172 bool fibril_mutex_is_locked(fibril_mutex_t *fm) 173 { 174 bool locked = false; 175 176 futex_down(&async_futex); 177 if (fm->counter <= 0) 178 locked = true; 179 futex_up(&async_futex); 180 181 return locked; 170 182 } 171 183 … … 230 242 { 231 243 futex_down(&async_futex); 232 assert(frw->readers || (frw->writers == 1));233 244 if (frw->readers) { 234 245 if (--frw->readers) { … … 296 307 void fibril_rwlock_read_unlock(fibril_rwlock_t *frw) 297 308 { 309 assert(fibril_rwlock_is_read_locked(frw)); 298 310 _fibril_rwlock_common_unlock(frw); 299 311 } … … 301 313 void fibril_rwlock_write_unlock(fibril_rwlock_t *frw) 302 314 { 315 assert(fibril_rwlock_is_write_locked(frw)); 303 316 _fibril_rwlock_common_unlock(frw); 317 } 318 319 bool fibril_rwlock_is_read_locked(fibril_rwlock_t *frw) 320 { 321 bool locked = false; 322 323 futex_down(&async_futex); 324 if (frw->readers) 325 locked = true; 326 futex_up(&async_futex); 327 328 return locked; 329 } 330 331 bool fibril_rwlock_is_write_locked(fibril_rwlock_t *frw) 332 { 333 bool locked = false; 334 335 futex_down(&async_futex); 336 if (frw->writers) { 337 assert(frw->writers == 1); 338 locked = true; 339 } 340 futex_up(&async_futex); 341 342 return locked; 343 } 344 345 bool fibril_rwlock_is_locked(fibril_rwlock_t *frw) 346 { 347 return fibril_rwlock_is_read_locked(frw) || 348 fibril_rwlock_is_write_locked(frw); 304 349 } 305 350 … … 314 359 { 315 360 awaiter_t wdata; 361 362 assert(fibril_mutex_is_locked(fm)); 316 363 317 364 if (timeout < 0) -
uspace/lib/c/generic/io/vprintf.c
ra3eeef45 ra676574 37 37 #include <unistd.h> 38 38 #include <io/printf_core.h> 39 #include <f utex.h>39 #include <fibril_synch.h> 40 40 #include <async.h> 41 41 #include <str.h> 42 42 43 static atomic_t printf_futex = FUTEX_INITIALIZER;43 static FIBRIL_MUTEX_INITIALIZE(printf_mutex); 44 44 45 45 static int vprintf_str_write(const char *str, size_t size, void *stream) … … 85 85 * Prevent other threads to execute printf_core() 86 86 */ 87 futex_down(&printf_futex); 88 89 /* 90 * Prevent other fibrils of the same thread 91 * to execute printf_core() 92 */ 93 async_serialize_start(); 87 fibril_mutex_lock(&printf_mutex); 94 88 95 89 int ret = printf_core(fmt, &ps, ap); 96 90 97 async_serialize_end(); 98 futex_up(&printf_futex); 91 fibril_mutex_unlock(&printf_mutex); 99 92 100 93 return ret; -
uspace/lib/c/generic/libc.c
ra3eeef45 ra676574 50 50 #include <ipc/ipc.h> 51 51 #include <async.h> 52 #include <async_rel.h>53 52 #include <as.h> 54 53 #include <loader/pcb.h> … … 66 65 __heap_init(); 67 66 __async_init(); 68 (void) async_rel_init();69 67 fibril_t *fibril = fibril_setup(); 70 68 __tcb_set(fibril->tcb); -
uspace/lib/c/generic/mem.c
ra3eeef45 ra676574 222 222 /** Compare two memory areas. 223 223 * 224 * @param s1 Pointer to the first area to compare. 225 * @param s2 Pointer to the second area to compare. 226 * @param len Size of the first area in bytes. Both areas must have 227 * the same length. 228 * @return If len is 0, return zero. If the areas match, return 229 * zero. Otherwise return non-zero. 230 */ 231 int bcmp(const char *s1, const char *s2, size_t len) 232 { 233 for (; len && *s1++ == *s2++; len--) 234 ; 224 * @param s1 Pointer to the first area to compare. 225 * @param s2 Pointer to the second area to compare. 226 * @param len Size of the first area in bytes. Both areas must have 227 * the same length. 228 * 229 * @return If len is 0, return zero. If the areas match, return 230 * zero. Otherwise return non-zero. 231 * 232 */ 233 int bcmp(const void *s1, const void *s2, size_t len) 234 { 235 uint8_t *u1 = (uint8_t *) s1; 236 uint8_t *u2 = (uint8_t *) s2; 237 238 for (; (len != 0) && (*u1++ == *u2++); len--); 239 235 240 return len; 236 241 } -
uspace/lib/c/generic/net/icmp_api.c
ra3eeef45 ra676574 89 89 tos, (sysarg_t) dont_fragment, NULL); 90 90 91 / / send the address91 /* Send the address */ 92 92 async_data_write_start(icmp_phone, addr, (size_t) addrlen); 93 93 -
uspace/lib/c/generic/net/inet.c
ra3eeef45 ra676574 64 64 switch (family) { 65 65 case AF_INET: 66 / / check the output buffer size66 /* Check output buffer size */ 67 67 if (length < INET_ADDRSTRLEN) 68 68 return ENOMEM; 69 69 70 / / fill the buffer with the IPv4 address70 /* Fill buffer with IPv4 address */ 71 71 snprintf(address, length, "%hhu.%hhu.%hhu.%hhu", 72 72 data[0], data[1], data[2], data[3]); … … 75 75 76 76 case AF_INET6: 77 / / check the output buffer size77 /* Check output buffer size */ 78 78 if (length < INET6_ADDRSTRLEN) 79 79 return ENOMEM; 80 80 81 / / fill the buffer with the IPv6 address81 /* Fill buffer with IPv6 address */ 82 82 snprintf(address, length, 83 83 "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:" … … 124 124 return EINVAL; 125 125 126 / / set the processing parameters126 /* Set processing parameters */ 127 127 switch (family) { 128 128 case AF_INET: … … 142 142 } 143 143 144 / / erase if no address144 /* Erase if no address */ 145 145 if (!address) { 146 146 bzero(data, count); … … 148 148 } 149 149 150 / / process the string from the beginning150 /* Process string from the beginning */ 151 151 next = address; 152 152 index = 0; 153 153 do { 154 / / if the actual character is set154 /* If the actual character is set */ 155 155 if (next && *next) { 156 156 157 / / if not on the first character157 /* If not on the first character */ 158 158 if (index) { 159 / / move to the next character159 /* Move to the next character */ 160 160 ++next; 161 161 } 162 162 163 / / parse the actual integral value163 /* Parse the actual integral value */ 164 164 value = strtoul(next, &last, base); 165 // remember the last problematic character 166 // should be either '.' or ':' but is ignored to be more 167 // generic 165 /* 166 * Remember the last problematic character 167 * should be either '.' or ':' but is ignored to be 168 * more generic 169 */ 168 170 next = last; 169 171 170 / / fill the address data byte by byte172 /* Fill the address data byte by byte */ 171 173 shift = bytes - 1; 172 174 do { 173 / / like little endian175 /* like little endian */ 174 176 data[index + shift] = value; 175 177 value >>= 8; … … 178 180 index += bytes; 179 181 } else { 180 / / erase the rest of the address182 /* Erase the rest of the address */ 181 183 bzero(data + index, count - index); 182 184 return EOK; -
uspace/lib/c/generic/net/modules.c
ra3eeef45 ra676574 63 63 int answer_count) 64 64 { 65 / / choose the most efficient answer function65 /* Choose the most efficient answer function */ 66 66 if (answer || (!answer_count)) { 67 67 switch (answer_count) { … … 178 178 int phone; 179 179 180 / / if no timeout is set180 /* If no timeout is set */ 181 181 if (timeout <= 0) 182 182 return async_connect_me_to_blocking(PHONE_NS, need, 0, 0); … … 187 187 return phone; 188 188 189 / / end if no time is left189 /* Abort if no time is left */ 190 190 if (timeout <= 0) 191 191 return ETIMEOUT; 192 192 193 / / wait the minimum of the module wait time and the timeout193 /* Wait the minimum of the module wait time and the timeout */ 194 194 usleep((timeout <= MODULE_WAIT_TIME) ? 195 195 timeout : MODULE_WAIT_TIME); … … 214 214 ipc_callid_t callid; 215 215 216 / / fetch the request216 /* Fetch the request */ 217 217 if (!async_data_read_receive(&callid, &length)) 218 218 return EINVAL; 219 219 220 / / check the requested data size220 /* Check the requested data size */ 221 221 if (length < data_length) { 222 222 async_data_read_finalize(callid, data, length); … … 224 224 } 225 225 226 / / send the data226 /* Send the data */ 227 227 return async_data_read_finalize(callid, data, data_length); 228 228 } … … 242 242 if (answer) { 243 243 IPC_SET_RETVAL(*answer, 0); 244 / / just to be precize244 /* Just to be precise */ 245 245 IPC_SET_IMETHOD(*answer, 0); 246 246 IPC_SET_ARG1(*answer, 0); -
uspace/lib/c/generic/net/packet.c
ra3eeef45 ra676574 191 191 } 192 192 gpm_destroy(&pm_globals.packet_map); 193 / / leave locked193 /* leave locked */ 194 194 } 195 195 -
uspace/lib/c/generic/net/socket_client.c
ra3eeef45 ra676574 220 220 fibril_rwlock_read_lock(&socket_globals.lock); 221 221 222 / / find the socket222 /* Find the socket */ 223 223 socket = sockets_find(socket_get_sockets(), 224 224 SOCKET_GET_SOCKET_ID(call)); … … 232 232 case NET_SOCKET_RECEIVED: 233 233 fibril_mutex_lock(&socket->receive_lock); 234 / / push the number of received packet fragments234 /* Push the number of received packet fragments */ 235 235 rc = dyn_fifo_push(&socket->received, 236 236 SOCKET_GET_DATA_FRAGMENTS(call), 237 237 SOCKET_MAX_RECEIVED_SIZE); 238 238 if (rc == EOK) { 239 / / signal the received packet239 /* Signal the received packet */ 240 240 fibril_condvar_signal(&socket->receive_signal); 241 241 } … … 244 244 245 245 case NET_SOCKET_ACCEPTED: 246 / / push the new socket identifier246 /* Push the new socket identifier */ 247 247 fibril_mutex_lock(&socket->accept_lock); 248 248 rc = dyn_fifo_push(&socket->accepted, 1, 249 249 SOCKET_MAX_ACCEPTED_SIZE); 250 250 if (rc == EOK) { 251 / / signal the accepted socket251 /* Signal the accepted socket */ 252 252 fibril_condvar_signal(&socket->accept_signal); 253 253 } … … 264 264 fibril_rwlock_write_lock(&socket->sending_lock); 265 265 266 / / set the data fragment size266 /* Set the data fragment size */ 267 267 socket->data_fragment_size = 268 268 SOCKET_GET_DATA_FRAGMENT_SIZE(call); … … 342 342 socket_id = 1; 343 343 ++count; 344 / / only this branch for last_id344 /* Only this branch for last_id */ 345 345 } else { 346 346 if (socket_id < INT_MAX) { … … 408 408 int rc; 409 409 410 / / find the appropriate service410 /* Find the appropriate service */ 411 411 switch (domain) { 412 412 case PF_INET: … … 457 457 return phone; 458 458 459 / / create a new socket structure459 /* Create a new socket structure */ 460 460 socket = (socket_t *) malloc(sizeof(socket_t)); 461 461 if (!socket) … … 465 465 fibril_rwlock_write_lock(&socket_globals.lock); 466 466 467 / / request a new socket467 /* Request a new socket */ 468 468 socket_id = socket_generate_new_id(); 469 469 if (socket_id <= 0) { … … 484 484 socket->header_size = (size_t) header_size; 485 485 486 / / finish the new socket initialization486 /* Finish the new socket initialization */ 487 487 socket_initialize(socket, socket_id, phone, service); 488 / / store the new socket488 /* Store the new socket */ 489 489 rc = sockets_add(socket_get_sockets(), socket_id, socket); 490 490 … … 531 531 fibril_rwlock_read_lock(&socket_globals.lock); 532 532 533 / / find the socket533 /* Find the socket */ 534 534 socket = sockets_find(socket_get_sockets(), socket_id); 535 535 if (!socket) { … … 538 538 } 539 539 540 / / request the message540 /* Request the message */ 541 541 message_id = async_send_3(socket->phone, message, 542 542 (sysarg_t) socket->socket_id, arg2, socket->service, NULL); 543 / / send the address543 /* Send the address */ 544 544 async_data_write_start(socket->phone, data, datalength); 545 545 … … 566 566 return EINVAL; 567 567 568 / / send the address568 /* Send the address */ 569 569 return socket_send_data(socket_id, NET_SOCKET_BIND, 0, my_addr, 570 570 (size_t) addrlen); … … 591 591 fibril_rwlock_read_lock(&socket_globals.lock); 592 592 593 / / find the socket593 /* Find the socket */ 594 594 socket = sockets_find(socket_get_sockets(), socket_id); 595 595 if (!socket) { … … 598 598 } 599 599 600 / / request listen backlog change600 /* Request listen backlog change */ 601 601 result = (int) async_req_3_0(socket->phone, NET_SOCKET_LISTEN, 602 602 (sysarg_t) socket->socket_id, (sysarg_t) backlog, socket->service); … … 634 634 fibril_rwlock_write_lock(&socket_globals.lock); 635 635 636 / / find the socket636 /* Find the socket */ 637 637 socket = sockets_find(socket_get_sockets(), socket_id); 638 638 if (!socket) { … … 643 643 fibril_mutex_lock(&socket->accept_lock); 644 644 645 / / wait for an accepted socket645 /* Wait for an accepted socket */ 646 646 ++ socket->blocked; 647 647 while (dyn_fifo_value(&socket->accepted) <= 0) { 648 648 fibril_rwlock_write_unlock(&socket_globals.lock); 649 649 fibril_condvar_wait(&socket->accept_signal, &socket->accept_lock); 650 / / drop the accept lock to avoid deadlock650 /* Drop the accept lock to avoid deadlock */ 651 651 fibril_mutex_unlock(&socket->accept_lock); 652 652 fibril_rwlock_write_lock(&socket_globals.lock); … … 655 655 -- socket->blocked; 656 656 657 / / create a new scoket657 /* Create a new socket */ 658 658 new_socket = (socket_t *) malloc(sizeof(socket_t)); 659 659 if (!new_socket) { … … 681 681 } 682 682 683 / / request accept683 /* Request accept */ 684 684 message_id = async_send_5(socket->phone, NET_SOCKET_ACCEPT, 685 685 (sysarg_t) socket->socket_id, 0, socket->service, 0, 686 686 new_socket->socket_id, &answer); 687 687 688 / / read address688 /* Read address */ 689 689 ipc_data_read_start(socket->phone, cliaddr, *addrlen); 690 690 fibril_rwlock_write_unlock(&socket_globals.lock); … … 695 695 result = EINVAL; 696 696 697 / / dequeue the accepted socket if successful697 /* Dequeue the accepted socket if successful */ 698 698 dyn_fifo_pop(&socket->accepted); 699 / / set address length699 /* Set address length */ 700 700 *addrlen = SOCKET_GET_ADDRESS_LENGTH(answer); 701 701 new_socket->data_fragment_size = 702 702 SOCKET_GET_DATA_FRAGMENT_SIZE(answer); 703 703 } else if (result == ENOTSOCK) { 704 / / empty the queue if no accepted sockets704 /* Empty the queue if no accepted sockets */ 705 705 while (dyn_fifo_pop(&socket->accepted) > 0) 706 706 ; … … 731 731 return EDESTADDRREQ; 732 732 733 / / send the address733 /* Send the address */ 734 734 return socket_send_data(socket_id, NET_SOCKET_CONNECT, 0, serv_addr, 735 735 addrlen); … … 744 744 int accepted_id; 745 745 746 / / destroy all accepted sockets746 /* Destroy all accepted sockets */ 747 747 while ((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0) 748 748 socket_destroy(sockets_find(socket_get_sockets(), accepted_id)); … … 780 780 } 781 781 782 / / request close782 /* Request close */ 783 783 rc = (int) async_req_3_0(socket->phone, NET_SOCKET_CLOSE, 784 784 (sysarg_t) socket->socket_id, 0, socket->service); … … 787 787 return rc; 788 788 } 789 / / free the socket structure789 /* Free the socket structure */ 790 790 socket_destroy(socket); 791 791 … … 833 833 fibril_rwlock_read_lock(&socket_globals.lock); 834 834 835 / / find socket835 /* Find socket */ 836 836 socket = sockets_find(socket_get_sockets(), socket_id); 837 837 if (!socket) { … … 842 842 fibril_rwlock_read_lock(&socket->sending_lock); 843 843 844 / / compute data fragment count844 /* Compute data fragment count */ 845 845 if (socket->data_fragment_size > 0) { 846 846 fragments = (datalength + socket->header_size) / … … 853 853 } 854 854 855 / / request send855 /* Request send */ 856 856 message_id = async_send_5(socket->phone, message, 857 857 (sysarg_t) socket->socket_id, … … 859 859 socket->service, (sysarg_t) flags, fragments, &answer); 860 860 861 / / send the address if given861 /* Send the address if given */ 862 862 if (!toaddr || 863 863 (async_data_write_start(socket->phone, toaddr, addrlen) == EOK)) { 864 864 if (fragments == 1) { 865 / / send all if only one fragment865 /* Send all if only one fragment */ 866 866 async_data_write_start(socket->phone, data, datalength); 867 867 } else { 868 / / send the first fragment868 /* Send the first fragment */ 869 869 async_data_write_start(socket->phone, data, 870 870 socket->data_fragment_size - socket->header_size); … … 872 872 socket->data_fragment_size - socket->header_size; 873 873 874 / / send the middle fragments874 /* Send the middle fragments */ 875 875 while (--fragments > 1) { 876 876 async_data_write_start(socket->phone, data, … … 880 880 } 881 881 882 / / send the last fragment882 /* Send the last fragment */ 883 883 async_data_write_start(socket->phone, data, 884 884 (datalength + socket->header_size) % … … 892 892 (SOCKET_GET_DATA_FRAGMENT_SIZE(answer) != 893 893 socket->data_fragment_size)) { 894 / / set the data fragment size894 /* Set the data fragment size */ 895 895 socket->data_fragment_size = 896 896 SOCKET_GET_DATA_FRAGMENT_SIZE(answer); … … 917 917 int send(int socket_id, void *data, size_t datalength, int flags) 918 918 { 919 / / without the address919 /* Without the address */ 920 920 return sendto_core(NET_SOCKET_SEND, socket_id, data, datalength, flags, 921 921 NULL, 0); … … 950 950 return EDESTADDRREQ; 951 951 952 / / with the address952 /* With the address */ 953 953 return sendto_core(NET_SOCKET_SENDTO, socket_id, data, datalength, 954 954 flags, toaddr, addrlen); … … 966 966 * read. The actual address length is set. Used only if 967 967 * fromaddr is not NULL. 968 * @return EOK on success. 968 * @return Positive received message size in bytes on success. 969 * @return Zero if no more data (other side closed the connection). 969 970 * @return ENOTSOCK if the socket is not found. 970 971 * @return EBADMEM if the data parameter is NULL. … … 972 973 * @return Other error codes as defined for the spcific message. 973 974 */ 974 static int975 static ssize_t 975 976 recvfrom_core(sysarg_t message, int socket_id, void *data, size_t datalength, 976 977 int flags, struct sockaddr *fromaddr, socklen_t *addrlen) … … 984 985 size_t index; 985 986 ipc_call_t answer; 987 ssize_t retval; 986 988 987 989 if (!data) … … 996 998 fibril_rwlock_read_lock(&socket_globals.lock); 997 999 998 / / find the socket1000 /* Find the socket */ 999 1001 socket = sockets_find(socket_get_sockets(), socket_id); 1000 1002 if (!socket) { … … 1004 1006 1005 1007 fibril_mutex_lock(&socket->receive_lock); 1006 / / wait for a received packet1008 /* Wait for a received packet */ 1007 1009 ++socket->blocked; 1008 while ((result = dyn_fifo_value(&socket->received)) < =0) {1010 while ((result = dyn_fifo_value(&socket->received)) < 0) { 1009 1011 fibril_rwlock_read_unlock(&socket_globals.lock); 1010 1012 fibril_condvar_wait(&socket->receive_signal, 1011 1013 &socket->receive_lock); 1012 1014 1013 / / drop the receive lock to avoid deadlock1015 /* Drop the receive lock to avoid deadlock */ 1014 1016 fibril_mutex_unlock(&socket->receive_lock); 1015 1017 fibril_rwlock_read_lock(&socket_globals.lock); … … 1019 1021 fragments = (size_t) result; 1020 1022 1021 // prepare lengths if more fragments 1023 if (fragments == 0) { 1024 /* No more data, other side has closed the connection. */ 1025 fibril_mutex_unlock(&socket->receive_lock); 1026 fibril_rwlock_read_unlock(&socket_globals.lock); 1027 return 0; 1028 } 1029 1030 /* Prepare lengths if more fragments */ 1022 1031 if (fragments > 1) { 1023 1032 lengths = (size_t *) malloc(sizeof(size_t) * fragments + … … 1029 1038 } 1030 1039 1031 / / request packet data1040 /* Request packet data */ 1032 1041 message_id = async_send_4(socket->phone, message, 1033 1042 (sysarg_t) socket->socket_id, 0, socket->service, 1034 1043 (sysarg_t) flags, &answer); 1035 1044 1036 / / read the address if desired1045 /* Read the address if desired */ 1037 1046 if(!fromaddr || 1038 1047 (async_data_read_start(socket->phone, fromaddr, 1039 1048 *addrlen) == EOK)) { 1040 / / read the fragment lengths1049 /* Read the fragment lengths */ 1041 1050 if (async_data_read_start(socket->phone, lengths, 1042 1051 sizeof(int) * (fragments + 1)) == EOK) { 1043 1052 if (lengths[fragments] <= datalength) { 1044 1053 1045 / / read all fragments if long enough1054 /* Read all fragments if long enough */ 1046 1055 for (index = 0; index < fragments; 1047 1056 ++index) { … … 1057 1066 1058 1067 free(lengths); 1059 } else { 1060 / / request packet data1068 } else { /* fragments == 1 */ 1069 /* Request packet data */ 1061 1070 message_id = async_send_4(socket->phone, message, 1062 1071 (sysarg_t) socket->socket_id, 0, socket->service, 1063 1072 (sysarg_t) flags, &answer); 1064 1073 1065 / / read the address if desired1074 /* Read the address if desired */ 1066 1075 if (!fromaddr || 1067 1076 (async_data_read_start(socket->phone, fromaddr, 1068 1077 *addrlen) == EOK)) { 1069 / / read all if only one fragment1078 /* Read all if only one fragment */ 1070 1079 async_data_read_start(socket->phone, data, datalength); 1071 1080 } … … 1075 1084 result = (int) ipc_result; 1076 1085 if (result == EOK) { 1077 / / dequeue the received packet1086 /* Dequeue the received packet */ 1078 1087 dyn_fifo_pop(&socket->received); 1079 / / return read data length1080 re sult= SOCKET_GET_READ_DATA_LENGTH(answer);1081 / / set address length1088 /* Return read data length */ 1089 retval = SOCKET_GET_READ_DATA_LENGTH(answer); 1090 /* Set address length */ 1082 1091 if (fromaddr && addrlen) 1083 1092 *addrlen = SOCKET_GET_ADDRESS_LENGTH(answer); 1093 } else { 1094 retval = (ssize_t) result; 1084 1095 } 1085 1096 1086 1097 fibril_mutex_unlock(&socket->receive_lock); 1087 1098 fibril_rwlock_read_unlock(&socket_globals.lock); 1088 return re sult;1099 return retval; 1089 1100 } 1090 1101 … … 1095 1106 * @param[in] datalength The data length. 1096 1107 * @param[in] flags Various receive flags. 1097 * @return EOK on success. 1108 * @return Positive received message size in bytes on success. 1109 * @return Zero if no more data (other side closed the connection). 1098 1110 * @return ENOTSOCK if the socket is not found. 1099 1111 * @return EBADMEM if the data parameter is NULL. … … 1102 1114 * message. 1103 1115 */ 1104 int recv(int socket_id, void *data, size_t datalength, int flags)1105 { 1106 / / without the address1116 ssize_t recv(int socket_id, void *data, size_t datalength, int flags) 1117 { 1118 /* Without the address */ 1107 1119 return recvfrom_core(NET_SOCKET_RECV, socket_id, data, datalength, 1108 1120 flags, NULL, NULL); … … 1118 1130 * @param[in,out] addrlen The address length. The maximum address length is 1119 1131 * read. The actual address length is set. 1120 * @return EOK on success. 1132 * @return Positive received message size in bytes on success. 1133 * @return Zero if no more data (other side closed the connection). 1121 1134 * @return ENOTSOCK if the socket is not found. 1122 1135 * @return EBADMEM if the data or fromaddr parameter is NULL. … … 1125 1138 * message. 1126 1139 */ 1127 int1140 ssize_t 1128 1141 recvfrom(int socket_id, void *data, size_t datalength, int flags, 1129 1142 struct sockaddr *fromaddr, socklen_t *addrlen) … … 1135 1148 return NO_DATA; 1136 1149 1137 / / with the address1150 /* With the address */ 1138 1151 return recvfrom_core(NET_SOCKET_RECVFROM, socket_id, data, datalength, 1139 1152 flags, fromaddr, addrlen); … … 1170 1183 fibril_rwlock_read_lock(&socket_globals.lock); 1171 1184 1172 / / find the socket1185 /* Find the socket */ 1173 1186 socket = sockets_find(socket_get_sockets(), socket_id); 1174 1187 if (!socket) { … … 1177 1190 } 1178 1191 1179 / / request option value1192 /* Request option value */ 1180 1193 message_id = async_send_3(socket->phone, NET_SOCKET_GETSOCKOPT, 1181 1194 (sysarg_t) socket->socket_id, (sysarg_t) optname, socket->service, 1182 1195 NULL); 1183 1196 1184 / / read the length1197 /* Read the length */ 1185 1198 if (async_data_read_start(socket->phone, optlen, 1186 1199 sizeof(*optlen)) == EOK) { 1187 / / read the value1200 /* Read the value */ 1188 1201 async_data_read_start(socket->phone, value, *optlen); 1189 1202 } … … 1212 1225 size_t optlen) 1213 1226 { 1214 / / send the value1227 /* Send the value */ 1215 1228 return socket_send_data(socket_id, NET_SOCKET_SETSOCKOPT, 1216 1229 (sysarg_t) optname, value, optlen); -
uspace/lib/c/generic/task.c
ra3eeef45 ra676574 65 65 * 66 66 * @return Zero on success or negative error code. 67 *68 67 */ 69 68 int task_set_name(const char *name) 70 69 { 71 70 return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name)); 71 } 72 73 /** Kill a task. 74 * 75 * @param task_id ID of task to kill. 76 * 77 * @return Zero on success or negative error code. 78 */ 79 80 int task_kill(task_id_t task_id) 81 { 82 return (int) __SYSCALL1(SYS_TASK_KILL, (sysarg_t) &task_id); 72 83 } 73 84
Note:
See TracChangeset
for help on using the changeset viewer.
