Changeset a33f0a6 in mainline for uspace/lib/net/tl/socket_core.c
- Timestamp:
- 2011-08-03T17:34:57Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1940326
- Parents:
- 52a79081 (diff), 3fab770 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/tl/socket_core.c
r52a79081 ra33f0a6 38 38 #include <packet_client.h> 39 39 #include <packet_remote.h> 40 41 40 #include <net/socket_codes.h> 42 41 #include <net/in.h> … … 44 43 #include <net/packet.h> 45 44 #include <net/modules.h> 46 47 45 #include <stdint.h> 48 46 #include <stdlib.h> 49 47 #include <errno.h> 50 51 48 #include <adt/dynamic_fifo.h> 52 49 #include <adt/int_map.h> … … 56 53 * switching to the sequence. 57 54 */ 58 #define SOCKET_ID_TRIES 55 #define SOCKET_ID_TRIES 100 59 56 60 57 /** Bound port sockets.*/ … … 72 69 INT_MAP_IMPLEMENT(socket_ports, socket_port_t); 73 70 74 /** Destroy sthe socket.71 /** Destroy the socket. 75 72 * 76 73 * If the socket is bound, the port is released. 77 * Release s all buffered packets, calls the release function and removesthe74 * Release all buffered packets, call the release function and remove the 78 75 * socket from the local sockets. 79 76 * 80 * @param[in] packet_phone The packet server phone to release buffered packets.81 * @param[in] socket The socket to be destroyed.82 * @param[in,out] local_sockets The local sockets to be updated.83 * @param[in,out] global_sockets The global sockets to be updated.84 * @param[in] socket_release The client release callback function.85 * /86 static void 87 s ocket_destroy_core(int packet_phone, socket_core_t *socket,77 * @param[in] sess Packet server session. 78 * @param[in] socket Socket to be destroyed. 79 * @param[in,out] local_sockets Local sockets to be updated. 80 * @param[in,out] global_sockets Global sockets to be updated. 81 * @param[in] socket_release Client release callback function. 82 * 83 */ 84 static void socket_destroy_core(async_sess_t *sess, socket_core_t *socket, 88 85 socket_cores_t *local_sockets, socket_ports_t *global_sockets, 89 86 void (* socket_release)(socket_core_t *socket)) 90 87 { 91 int packet_id;92 93 88 /* If bound */ 94 89 if (socket->port) { … … 98 93 99 94 /* Release all received packets */ 95 int packet_id; 100 96 while ((packet_id = dyn_fifo_pop(&socket->received)) >= 0) 101 pq_release_remote( packet_phone, packet_id);102 97 pq_release_remote(sess, packet_id); 98 103 99 dyn_fifo_destroy(&socket->received); 104 100 dyn_fifo_destroy(&socket->accepted); 105 101 106 102 if (socket_release) 107 103 socket_release(socket); 108 104 109 105 socket_cores_exclude(local_sockets, socket->socket_id, free); 110 106 } 111 107 112 /** Destroy slocal sockets.113 * 114 * Release s all buffered packets and callsthe release function for each of the108 /** Destroy local sockets. 109 * 110 * Release all buffered packets and call the release function for each of the 115 111 * sockets. 116 112 * 117 * @param[in] packet_phone The packet server phone to release buffered packets.118 * @param[in] local_sockets The local sockets to be destroyed.119 * @param[in,out] global_sockets The global sockets to be updated.120 * @param[in] socket_release The client release callback function.121 * /122 void 123 socket_cores_release(int packet_phone, socket_cores_t *local_sockets,113 * @param[in] sess Packet server session. 114 * @param[in] local_sockets Local sockets to be destroyed. 115 * @param[in,out] global_sockets Global sockets to be updated. 116 * @param[in] socket_release Client release callback function. 117 * 118 */ 119 void socket_cores_release(async_sess_t *sess, socket_cores_t *local_sockets, 124 120 socket_ports_t *global_sockets, 125 121 void (* socket_release)(socket_core_t *socket)) 126 122 { 127 int index;128 129 123 if (!socket_cores_is_valid(local_sockets)) 130 124 return; 131 125 132 126 local_sockets->magic = 0; 133 127 128 int index; 134 129 for (index = 0; index < local_sockets->next; ++index) { 135 130 if (socket_cores_item_is_valid(&local_sockets->items[index])) { 136 131 local_sockets->items[index].magic = 0; 137 132 138 133 if (local_sockets->items[index].value) { 139 socket_destroy_core( packet_phone,134 socket_destroy_core(sess, 140 135 local_sockets->items[index].value, 141 136 local_sockets, global_sockets, … … 146 141 } 147 142 } 148 143 149 144 free(local_sockets->items); 150 145 } … … 406 401 } 407 402 408 /** Creates a new socket. 409 * 410 * @param[in,out] local_sockets The local sockets to be updated. 411 * @param[in] app_phone The application phone. 412 * @param[in] specific_data The socket specific data. 413 * @param[in,out] socket_id The new socket identifier. A new identifier is 414 * chosen if set to zero or negative. A negative identifier 415 * is chosen if set to negative. 416 * @return EOK on success. 417 * @return EINVAL if the socket_id parameter is NULL. 418 * @return ENOMEM if there is not enough memory left. 419 */ 420 int 421 socket_create(socket_cores_t *local_sockets, int app_phone, 403 /** Create a new socket. 404 * 405 * @param[in,out] local_sockets Local sockets to be updated. 406 * @param[in] sess Application session. 407 * @param[in] specific_data Socket specific data. 408 * @param[in,out] socket_id New socket identifier. A new identifier 409 * is chosen if set to zero or negative. 410 * A negative identifier is chosen if set 411 * to negative. 412 * 413 * @return EOK on success. 414 * @return EINVAL if the socket_id parameter is NULL. 415 * @return ENOMEM if there is not enough memory left. 416 * 417 */ 418 int socket_create(socket_cores_t *local_sockets, async_sess_t* sess, 422 419 void *specific_data, int *socket_id) 423 420 { … … 446 443 447 444 /* Initialize */ 448 socket-> phone = app_phone;445 socket->sess = sess; 449 446 socket->port = -1; 450 447 socket->key = NULL; … … 475 472 } 476 473 477 /** Destroy sthe socket.474 /** Destroy the socket. 478 475 * 479 476 * If the socket is bound, the port is released. 480 * Release s all buffered packets, calls the release function and removesthe477 * Release all buffered packets, call the release function and remove the 481 478 * socket from the local sockets. 482 479 * 483 * @param[in] packet_phone The packet server phone to release buffered packets. 484 * @param[in] socket_id The socket identifier. 485 * @param[in,out] local_sockets The local sockets to be updated. 486 * @param[in,out] global_sockets The global sockets to be updated. 487 * @param[in] socket_release The client release callback function. 488 * @return EOK on success. 489 * @return ENOTSOCK if the socket is not found. 480 * @param[in] sess Packet server session. 481 * @param[in] socket_id Socket identifier. 482 * @param[in,out] local_sockets Local sockets to be updated. 483 * @param[in,out] global_sockets Global sockets to be updated. 484 * @param[in] socket_release Client release callback function. 485 * 486 * @return EOK on success. 487 * @return ENOTSOCK if the socket is not found. 488 * 490 489 */ 491 490 int 492 socket_destroy( int packet_phone, int socket_id, socket_cores_t *local_sockets,491 socket_destroy(async_sess_t *sess, int socket_id, socket_cores_t *local_sockets, 493 492 socket_ports_t *global_sockets, 494 493 void (*socket_release)(socket_core_t *socket)) 495 494 { 496 socket_core_t *socket;497 int accepted_id;498 499 495 /* Find the socket */ 500 socket = socket_cores_find(local_sockets, socket_id);496 socket_core_t *socket = socket_cores_find(local_sockets, socket_id); 501 497 if (!socket) 502 498 return ENOTSOCK; 503 499 504 500 /* Destroy all accepted sockets */ 501 int accepted_id; 505 502 while ((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0) 506 socket_destroy( packet_phone, accepted_id, local_sockets,503 socket_destroy(sess, accepted_id, local_sockets, 507 504 global_sockets, socket_release); 508 505 509 socket_destroy_core( packet_phone, socket, local_sockets, global_sockets,506 socket_destroy_core(sess, socket, local_sockets, global_sockets, 510 507 socket_release); 511 508
Note:
See TracChangeset
for help on using the changeset viewer.