Changeset 1916d1f in mainline for uspace/lib/net/tl/socket_core.c


Ignore:
Timestamp:
2011-07-12T13:41:26Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
50fc490
Parents:
11809eab (diff), 6817eba (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 libposix changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/tl/socket_core.c

    r11809eab r1916d1f  
    3838#include <packet_client.h>
    3939#include <packet_remote.h>
    40 
    4140#include <net/socket_codes.h>
    4241#include <net/in.h>
     
    4443#include <net/packet.h>
    4544#include <net/modules.h>
    46 
    4745#include <stdint.h>
    4846#include <stdlib.h>
    4947#include <errno.h>
    50 
    5148#include <adt/dynamic_fifo.h>
    5249#include <adt/int_map.h>
     
    5653 * switching to the sequence.
    5754 */
    58 #define SOCKET_ID_TRIES 100
     55#define SOCKET_ID_TRIES  100
    5956
    6057/** Bound port sockets.*/
     
    7269INT_MAP_IMPLEMENT(socket_ports, socket_port_t);
    7370
    74 /** Destroys the socket.
     71/** Destroy the socket.
    7572 *
    7673 * If the socket is bound, the port is released.
    77  * Releases all buffered packets, calls the release function and removes the
     74 * Release all buffered packets, call the release function and remove the
    7875 * socket from the local sockets.
    7976 *
    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 socket_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 */
     84static void socket_destroy_core(async_sess_t *sess, socket_core_t *socket,
    8885    socket_cores_t *local_sockets, socket_ports_t *global_sockets,
    8986    void (* socket_release)(socket_core_t *socket))
    9087{
    91         int packet_id;
    92 
    9388        /* If bound */
    9489        if (socket->port) {
     
    9893       
    9994        /* Release all received packets */
     95        int packet_id;
    10096        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       
    10399        dyn_fifo_destroy(&socket->received);
    104100        dyn_fifo_destroy(&socket->accepted);
    105 
     101       
    106102        if (socket_release)
    107103                socket_release(socket);
    108 
     104       
    109105        socket_cores_exclude(local_sockets, socket->socket_id, free);
    110106}
    111107
    112 /** Destroys local sockets.
    113  *
    114  * Releases all buffered packets and calls the release function for each of the
     108/** Destroy local sockets.
     109 *
     110 * Release all buffered packets and call the release function for each of the
    115111 * sockets.
    116112 *
    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 */
     119void socket_cores_release(async_sess_t *sess, socket_cores_t *local_sockets,
    124120    socket_ports_t *global_sockets,
    125121    void (* socket_release)(socket_core_t *socket))
    126122{
    127         int index;
    128 
    129123        if (!socket_cores_is_valid(local_sockets))
    130124                return;
    131 
     125       
    132126        local_sockets->magic = 0;
    133 
     127       
     128        int index;
    134129        for (index = 0; index < local_sockets->next; ++index) {
    135130                if (socket_cores_item_is_valid(&local_sockets->items[index])) {
    136131                        local_sockets->items[index].magic = 0;
    137 
     132                       
    138133                        if (local_sockets->items[index].value) {
    139                                 socket_destroy_core(packet_phone,
     134                                socket_destroy_core(sess,
    140135                                    local_sockets->items[index].value,
    141136                                    local_sockets, global_sockets,
     
    146141                }
    147142        }
    148 
     143       
    149144        free(local_sockets->items);
    150145}
     
    406401}
    407402
    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 */
     418int socket_create(socket_cores_t *local_sockets, async_sess_t* sess,
    422419    void *specific_data, int *socket_id)
    423420{
     
    446443       
    447444        /* Initialize */
    448         socket->phone = app_phone;
     445        socket->sess = sess;
    449446        socket->port = -1;
    450447        socket->key = NULL;
     
    475472}
    476473
    477 /** Destroys the socket.
     474/** Destroy the socket.
    478475 *
    479476 * If the socket is bound, the port is released.
    480  * Releases all buffered packets, calls the release function and removes the
     477 * Release all buffered packets, call the release function and remove the
    481478 * socket from the local sockets.
    482479 *
    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 *
    490489 */
    491490int
    492 socket_destroy(int packet_phone, int socket_id, socket_cores_t *local_sockets,
     491socket_destroy(async_sess_t *sess, int socket_id, socket_cores_t *local_sockets,
    493492    socket_ports_t *global_sockets,
    494493    void (*socket_release)(socket_core_t *socket))
    495494{
    496         socket_core_t *socket;
    497         int accepted_id;
    498 
    499495        /* Find the socket */
    500         socket = socket_cores_find(local_sockets, socket_id);
     496        socket_core_t *socket = socket_cores_find(local_sockets, socket_id);
    501497        if (!socket)
    502498                return ENOTSOCK;
    503499       
    504500        /* Destroy all accepted sockets */
     501        int accepted_id;
    505502        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,
    507504                    global_sockets, socket_release);
    508505       
    509         socket_destroy_core(packet_phone, socket, local_sockets, global_sockets,
     506        socket_destroy_core(sess, socket, local_sockets, global_sockets,
    510507            socket_release);
    511508       
Note: See TracChangeset for help on using the changeset viewer.