Changeset 137f8aa in mainline for uspace/lib/net/include/socket_core.h


Ignore:
Timestamp:
2010-10-15T20:53:02Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b01f878
Parents:
25d2de69
Message:

Cleanup socket_core.[ch].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/include/socket_core.h

    r25d2de69 r137f8aa  
    2727 */
    2828
    29 /** @addtogroup socket
     29/** @addtogroup libnet
    3030 *  @{
    3131 */
    3232
    3333/** @file
    34  *  Socket common core.
     34 * Socket common core.
    3535 */
    3636
    37 #ifndef __NET_SOCKET_CORE_H__
    38 #define __NET_SOCKET_CORE_H__
     37#ifndef LIBNET_SOCKET_CORE_H_
     38#define LIBNET_SOCKET_CORE_H_
    3939
    4040#include <sys/types.h>
    41 
    42 #include <net/in.h>
    43 #include <net/device.h>
    4441#include <adt/generic_char_map.h>
    4542#include <adt/dynamic_fifo.h>
    4643#include <adt/int_map.h>
     44#include <net/in.h>
     45#include <net/device.h>
    4746#include <net/packet.h>
    4847
    49 /** Initial size of the received packet queue.
    50  */
     48/** Initial size of the received packet queue. */
    5149#define SOCKET_INITIAL_RECEIVED_SIZE    4
    5250
    53 /** Maximum size of the received packet queue.
    54  */
    55 #define SOCKET_MAX_RECEIVED_SIZE                0
     51/** Maximum size of the received packet queue. */
     52#define SOCKET_MAX_RECEIVED_SIZE        0
    5653
    57 /** Initial size of the sockets for acceptance queue.
    58  */
     54/** Initial size of the sockets for acceptance queue. */
    5955#define SOCKET_INITIAL_ACCEPTED_SIZE    1
    6056
    61 /** Maximum size of the sockets for acceptance queue.
    62  */
    63 #define SOCKET_MAX_ACCEPTEDED_SIZE              0
     57/** Maximum size of the sockets for acceptance queue. */
     58#define SOCKET_MAX_ACCEPTEDED_SIZE      0
    6459
    65 /** Listening sockets' port map key.
    66  */
     60/** Listening sockets' port map key. */
    6761#define SOCKET_MAP_KEY_LISTENING        "L"
    6862
    6963/** Type definition of the socket core.
    70  *  @see socket_core
     64 * @see socket_core
    7165 */
    72 typedef struct socket_core      socket_core_t;
     66typedef struct socket_core socket_core_t;
    7367
    7468/** Type definition of the socket core pointer.
    75  *  @see socket_core
     69 * @see socket_core
    7670 */
    77 typedef socket_core_t * socket_core_ref;
     71typedef socket_core_t *socket_core_ref;
    7872
    7973/** Type definition of the socket port.
    80  *  @see socket_port
     74 * @see socket_port
    8175 */
    82 typedef struct socket_port      socket_port_t;
     76typedef struct socket_port socket_port_t;
    8377
    8478/** Type definition of the socket port pointer.
    85  *  @see socket_port
     79 * @see socket_port
    8680 */
    87 typedef socket_port_t * socket_port_ref;
     81typedef socket_port_t *socket_port_ref;
    8882
    89 /** Socket core.
    90  */
    91 struct socket_core{
    92         /** Socket identifier.
    93          */
     83/** Socket core. */
     84struct socket_core {
     85        /** Socket identifier. */
    9486        int socket_id;
    95         /** Client application phone.
    96          */
     87        /** Client application phone. */
    9788        int phone;
    98         /** Bound port.
    99          */
     89        /** Bound port. */
    10090        int port;
    101         /** Received packets queue.
    102          */
     91        /** Received packets queue. */
    10392        dyn_fifo_t received;
    104         /** Sockets for acceptance queue.
    105          */
     93        /** Sockets for acceptance queue. */
    10694        dyn_fifo_t accepted;
    107         /** Protocol specific data.
    108          */
    109         void * specific_data;
    110         /** Socket ports map key.
    111          */
    112         const char * key;
    113         /** Length of the Socket ports map key.
    114          */
     95        /** Protocol specific data. */
     96        void *specific_data;
     97        /** Socket ports map key. */
     98        const char *key;
     99        /** Length of the Socket ports map key. */
    115100        size_t key_length;
    116101};
    117102
    118103/** Sockets map.
    119  *  The key is the socket identifier.
     104 * The key is the socket identifier.
    120105 */
    121106INT_MAP_DECLARE(socket_cores, socket_core_t);
    122107
    123108/** Bount port sockets map.
    124  *  The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas the other use the remote addresses.
     109 *
     110 * The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas
     111 * the other use the remote addresses.
    125112 */
    126113GENERIC_CHAR_MAP_DECLARE(socket_port_map, socket_core_ref);
    127114
    128115/** Ports map.
    129  *  The key is the port number.
     116 * The key is the port number.
    130117 */
    131118INT_MAP_DECLARE(socket_ports, socket_port_t);
    132119
    133 /** Destroys local sockets.
    134  *  Releases all buffered packets and calls the release function for each of the sockets.
    135  *  @param[in] packet_phone The packet server phone to release buffered packets.
    136  *  @param[in] local_sockets The local sockets to be destroyed.
    137  *  @param[in,out] global_sockets The global sockets to be updated.
    138  *  @param[in] socket_release The client release callback function.
    139  */
    140 extern void socket_cores_release(int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket));
    141 
    142 /** Binds the socket to the port.
    143  *  The address port is used if set, a free port is used if not.
    144  *  @param[in] local_sockets The local sockets to be searched.
    145  *  @param[in,out] global_sockets The global sockets to be updated.
    146  *  @param[in] socket_id The new socket identifier.
    147  *  @param[in] addr The address to be bound to.
    148  *  @param[in] addrlen The address length.
    149  *  @param[in] free_ports_start The minimum free port.
    150  *  @param[in] free_ports_end The maximum free port.
    151  *  @param[in] last_used_port The last used free port.
    152  *  @returns EOK on success.
    153  *  @returns ENOTSOCK if the socket was not found.
    154  *  @returns EAFNOSUPPORT if the address family is not supported.
    155  *  @returns EADDRINUSE if the port is already in use.
    156  *  @returns Other error codes as defined for the socket_bind_free_port() function.
    157  *  @returns Other error codes as defined for the socket_bind_insert() function.
    158  */
    159 extern int socket_bind(socket_cores_ref local_sockets, socket_ports_ref global_sockets, int socket_id, void * addr, size_t addrlen, int free_ports_start, int free_ports_end, int last_used_port);
    160 
    161 /** Binds the socket to a free port.
    162  *  The first free port is used.
    163  *  @param[in,out] global_sockets The global sockets to be updated.
    164  *  @param[in,out] socket The socket to be bound.
    165  *  @param[in] free_ports_start The minimum free port.
    166  *  @param[in] free_ports_end The maximum free port.
    167  *  @param[in] last_used_port The last used free port.
    168  *  @returns EOK on success.
    169  *  @returns ENOTCONN if no free port was found.
    170  *  @returns Other error codes as defined for the socket_bind_insert() function.
    171  */
    172 extern int socket_bind_free_port(socket_ports_ref global_sockets, socket_core_ref socket, int free_ports_start, int free_ports_end, int last_used_port);
    173 
    174 /** Creates a new socket.
    175  *  @param[in,out] local_sockets The local sockets to be updated.
    176  *  @param[in] app_phone The application phone.
    177  *  @param[in] specific_data The socket specific data.
    178  *  @param[in,out] socket_id The new socket identifier. A new identifier is chosen if set to zero (0) or negative. A negative identifier is chosen if set to negative.
    179  *  @returns EOK on success.
    180  *  @returns EINVAL if the socket_id parameter is NULL.
    181  *  @returns ENOMEM if there is not enough memory left.
    182  */
    183 extern int socket_create(socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id);
    184 
    185 /** Destroys the socket.
    186  *  If the socket is bound, the port is released.
    187  *  Releases all buffered packets, calls the release function and removes the socket from the local sockets.
    188  *  @param[in] packet_phone The packet server phone to release buffered packets.
    189  *  @param[in] socket_id The socket identifier.
    190  *  @param[in,out] local_sockets The local sockets to be updated.
    191  *  @param[in,out] global_sockets The global sockets to be updated.
    192  *  @param[in] socket_release The client release callback function.
    193  *  @returns EOK on success.
    194  *  @returns ENOTSOCK if the socket is not found.
    195  */
    196 extern int socket_destroy(int packet_phone, int socket_id, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket));
    197 
    198 /** Replies the packet or the packet queue data to the application via the socket.
    199  *  Uses the current message processing fibril.
    200  *  @param[in] packet The packet to be transfered.
    201  *  @param[out] length The total data length.
    202  *  @returns EOK on success.
    203  *  @returns EBADMEM if the length parameter is NULL.
    204  *  @returns ENOMEM if there is not enough memory left.
    205  *  @returns Other error codes as defined for the data_reply() function.
    206  */
    207 extern int socket_reply_packets(packet_t packet, size_t * length);
    208 
    209 /** Finds the bound port socket.
    210  *  @param[in] global_sockets The global sockets to be searched.
    211  *  @param[in] port The port number.
    212  *  @param[in] key The socket key identifier.
    213  *  @param[in] key_length The socket key length.
    214  *  @returns The found socket.
    215  *  @returns NULL if no socket was found.
    216  */
    217 extern socket_core_ref socket_port_find(socket_ports_ref global_sockets, int port, const char * key, size_t key_length);
    218 
    219 /** Releases the socket port.
    220  *  If the socket is bound the port entry is released.
    221  *  If there are no more port entries the port is release.
    222  *  @param[in] global_sockets The global sockets to be updated.
    223  *  @param[in] socket The socket to be unbound.
    224  */
    225 extern void socket_port_release(socket_ports_ref global_sockets, socket_core_ref socket);
    226 
    227 /** Adds the socket to an already bound port.
    228  *  @param[in] global_sockets The global sockets to be updated.
    229  *  @param[in] port The port number to be bound to.
    230  *  @param[in] socket The socket to be added.
    231  *  @param[in] key The socket key identifier.
    232  *  @param[in] key_length The socket key length.
    233  *  @returns EOK on success.
    234  *  @returns ENOENT if the port is not already used.
    235  *  @returns Other error codes as defined for the socket_port_add_core() function.
    236  */
    237 extern int socket_port_add(socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length);
     120extern void socket_cores_release(int, socket_cores_ref, socket_ports_ref,
     121    void (*)(socket_core_ref));
     122extern int socket_bind(socket_cores_ref, socket_ports_ref, int, void *, size_t,
     123    int, int, int);
     124extern int socket_bind_free_port(socket_ports_ref, socket_core_ref, int, int,
     125    int);
     126extern int socket_create(socket_cores_ref, int, void *, int *);
     127extern int socket_destroy(int, int, socket_cores_ref, socket_ports_ref,
     128    void (*)(socket_core_ref));
     129extern int socket_reply_packets(packet_t, size_t *);
     130extern socket_core_ref socket_port_find(socket_ports_ref, int, const char *,
     131    size_t);
     132extern void socket_port_release(socket_ports_ref, socket_core_ref);
     133extern int socket_port_add(socket_ports_ref, int, socket_core_ref,
     134    const char *, size_t);
    238135
    239136#endif
Note: See TracChangeset for help on using the changeset viewer.