Changeset 14f1db0 in mainline for uspace/lib/socket


Ignore:
Timestamp:
2010-04-09T12:54:57Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1caa3c2
Parents:
24ab58b3
Message:

networking overhaul:

  • separation of conserns
  • removal of (almost all) overlaping symbols, libnetif is not needed anymore
  • again, it is possible to build the networking in multiple architecture configurations (however, currently only the bundling netif and nil layers is supported, more to come)
  • code style updates and fixes (still a huge amount of work to do)
Location:
uspace/lib/socket
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/socket/generic/net_modules.c

    r24ab58b3 r14f1db0  
    7777}
    7878
    79 int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver){
     79/** Create bidirectional connection with the needed module service and registers the message receiver.
     80 *
     81 * @param[in] need            The needed module service.
     82 * @param[in] arg1            The first parameter.
     83 * @param[in] arg2            The second parameter.
     84 * @param[in] arg3            The third parameter.
     85 * @param[in] client_receiver The message receiver.
     86 *
     87 * @return The phone of the needed service.
     88 * @return Other error codes as defined for the ipc_connect_to_me() function.
     89 *
     90 */
     91int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3,
     92    async_client_conn_t client_receiver)
     93{
    8094        return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0);
    8195}
    8296
    83 int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout){
     97/** Create bidirectional connection with the needed module service and registers the message receiver.
     98 *
     99 * @param[in] need            The needed module service.
     100 * @param[in] arg1            The first parameter.
     101 * @param[in] arg2            The second parameter.
     102 * @param[in] arg3            The third parameter.
     103 * @param[in] client_receiver The message receiver.
     104 * @param[in] timeout         The connection timeout in microseconds.
     105 *                            No timeout if set to zero (0).
     106 *
     107 * @return The phone of the needed service.
     108 * @return ETIMEOUT if the connection timeouted.
     109 * @return Other error codes as defined for the ipc_connect_to_me() function.
     110 *
     111 */
     112int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2,
     113    ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
     114{
    84115        ERROR_DECLARE;
    85 
    86         int phone;
    87         ipcarg_t phonehash;
    88 
    89         // connect to the needed service
    90         phone = connect_to_service_timeout(need, timeout);
    91         // if connected
    92         if(phone >= 0){
    93                 // request the bidirectional connection
    94                 if(ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash))){
     116       
     117        /* Connect to the needed service */
     118        int phone = connect_to_service_timeout(need, timeout);
     119        if (phone >= 0) {
     120                /* Request the bidirectional connection */
     121                ipcarg_t phonehash;
     122                if (ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3,
     123                    &phonehash))) {
    95124                        ipc_hangup(phone);
    96125                        return ERROR_CODE;
     
    98127                async_new_connection(phonehash, 0, NULL, client_receiver);
    99128        }
     129       
    100130        return phone;
    101131}
  • uspace/lib/socket/generic/socket_core.c

    r24ab58b3 r14f1db0  
    9090        // release all received packets
    9191        while((packet_id = dyn_fifo_pop(&socket->received)) >= 0){
    92                 pq_release(packet_phone, packet_id);
     92                pq_release_local(packet_phone, packet_id);
    9393        }
    9494        dyn_fifo_destroy(&socket->received);
  • uspace/lib/socket/include/net_messages.h

    r24ab58b3 r14f1db0  
    462462/*@}*/
    463463
    464 /** Notifies the module about the device state change.
    465  *  @param[in] phone The service module phone.
    466  *  @param[in] message The service specific message.
    467  *  @param[in] device_id The device identifier.
    468  *  @param[in] state The new device state.
    469  *  @param[in] target The target module service.
    470  *  @returns EOK on success.
    471  */
    472 static inline int generic_device_state_msg(int phone, int message, device_id_t device_id, int state, services_t target){
    473         async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) state, target);
     464/** Notify the module about the device state change.
     465 *
     466 * @param[in] phone     The service module phone.
     467 * @param[in] message   The service specific message.
     468 * @param[in] device_id The device identifier.
     469 * @param[in] state     The new device state.
     470 * @param[in] target    The target module service.
     471 *
     472 * @return EOK on success.
     473 *
     474 */
     475static inline int generic_device_state_msg_remote(int phone, int message,
     476    device_id_t device_id, int state, services_t target)
     477{
     478        async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     479            (ipcarg_t) state, target);
     480       
    474481        return EOK;
    475482}
    476483
    477 /** Notifies a module about the device.
    478  *  @param[in] phone The service module phone.
    479  *  @param[in] message The service specific message.
    480  *  @param[in] device_id The device identifier.
    481  *  @param[in] arg2 The second argument of the message.
    482  *  @param[in] service The device module service.
    483  *  @returns EOK on success.
    484  *  @returns Other error codes as defined for the specific service message.
    485  */
    486 static inline int generic_device_req(int phone, int message, device_id_t device_id, int arg2, services_t service){
    487         return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) arg2, (ipcarg_t) service);
     484/** Notify a module about the device.
     485 *
     486 * @param[in] phone     The service module phone.
     487 * @param[in] message   The service specific message.
     488 * @param[in] device_id The device identifier.
     489 * @param[in] arg2      The second argument of the message.
     490 * @param[in] service   The device module service.
     491 *
     492 * @return EOK on success.
     493 * @return Other error codes as defined for the specific service message.
     494 *
     495 */
     496static inline int generic_device_req_remote(int phone, int message,
     497    device_id_t device_id, int arg2, services_t service)
     498{
     499        return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     500            (ipcarg_t) arg2, (ipcarg_t) service);
    488501}
    489502
     
    521534}
    522535
    523 /** Returns the device packet dimension for sending.
    524  *  @param[in] phone The service module phone.
    525  *  @param[in] message The service specific message.
    526  *  @param[in] device_id The device identifier.
    527  *  @param[out] packet_dimension The packet dimension.
    528  *  @returns EOK on success.
    529  *  @returns EBADMEM if the packet_dimension parameter is NULL.
    530  *  @returns Other error codes as defined for the specific service message.
    531  */
    532 static inline int generic_packet_size_req(int phone, int message, device_id_t device_id, packet_dimension_ref packet_dimension){
    533         ipcarg_t result;
     536/** Return the device packet dimension for sending.
     537 *
     538 * @param[in]  phone            The service module phone.
     539 * @param[in]  message          The service specific message.
     540 * @param[in]  device_id        The device identifier.
     541 * @param[out] packet_dimension The packet dimension.
     542 *
     543 * @return EOK on success.
     544 * @return EBADMEM if the packet_dimension parameter is NULL.
     545 * @return Other error codes as defined for the specific service message.
     546 *
     547 */
     548static inline int generic_packet_size_req_remote(int phone, int message,
     549    device_id_t device_id, packet_dimension_ref packet_dimension)
     550{
     551        if (!packet_dimension)
     552                return EBADMEM;
     553       
     554        ipcarg_t addr_len;
    534555        ipcarg_t prefix;
    535556        ipcarg_t content;
    536557        ipcarg_t suffix;
    537         ipcarg_t addr_len;
    538 
    539         if(! packet_dimension){
    540                 return EBADMEM;
    541         }
    542         result = async_req_1_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, &addr_len, &prefix, &content, &suffix);
     558       
     559        ipcarg_t result = async_req_1_4(phone, (ipcarg_t) message,
     560            (ipcarg_t) device_id, &addr_len, &prefix, &content, &suffix);
     561       
    543562        packet_dimension->prefix = (size_t) prefix;
    544563        packet_dimension->content = (size_t) content;
    545564        packet_dimension->suffix = (size_t) suffix;
    546565        packet_dimension->addr_len = (size_t) addr_len;
     566       
    547567        return (int) result;
    548568}
    549569
    550 /** Passes the packet queue to the module.
    551  *  @param[in] phone The service module phone.
    552  *  @param[in] message The service specific message.
    553  *  @param[in] device_id The device identifier.
    554  *  @param[in] packet_id The received packet or the received packet queue identifier.
    555  *  @param[in] target The target module service.
    556  *  @param[in] error The error module service.
    557  *  @returns EOK on success.
    558  */
    559 static inline int generic_received_msg(int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t target, services_t error){
    560         if(error){
    561                 async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) target, (ipcarg_t) error);
    562         }else{
    563                 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) target);
    564         }
     570/** Pass the packet queue to the module.
     571 *
     572 * @param[in] phone     The service module phone.
     573 * @param[in] message   The service specific message.
     574 * @param[in] device_id The device identifier.
     575 * @param[in] packet_id The received packet or the received packet queue
     576 *                      identifier.
     577 * @param[in] target    The target module service.
     578 * @param[in] error     The error module service.
     579 *
     580 * @return EOK on success.
     581 *
     582 */
     583static inline int generic_received_msg_remote(int phone, int message,
     584    device_id_t device_id, packet_id_t packet_id, services_t target,
     585    services_t error)
     586{
     587        if (error)
     588                async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     589                    (ipcarg_t) packet_id, (ipcarg_t) target, (ipcarg_t) error);
     590        else
     591                async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     592                    (ipcarg_t) packet_id, (ipcarg_t) target);
     593       
    565594        return EOK;
    566595}
    567596
    568 /** Sends the packet queue.
    569  *  @param[in] phone The service module phone.
    570  *  @param[in] message The service specific message.
    571  *  @param[in] device_id The device identifier.
    572  *  @param[in] packet_id The packet or the packet queue identifier.
    573  *  @param[in] sender The sending module service.
    574  *  @param[in] error The error module service.
    575  *  @returns EOK on success.
    576  */
    577 static inline int generic_send_msg(int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t sender, services_t error){
    578         if(error){
    579                 async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error);
    580         }else{
    581                 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender);
    582         }
     597/** Send the packet queue.
     598 *
     599 * @param[in] phone     The service module phone.
     600 * @param[in] message   The service specific message.
     601 * @param[in] device_id The device identifier.
     602 * @param[in] packet_id The packet or the packet queue identifier.
     603 * @param[in] sender    The sending module service.
     604 * @param[in] error     The error module service.
     605 *
     606 * @return EOK on success.
     607 *
     608 */
     609static inline int generic_send_msg_remote(int phone, int message,
     610    device_id_t device_id, packet_id_t packet_id, services_t sender,
     611    services_t error)
     612{
     613        if (error)
     614                async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     615                    (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error);
     616        else
     617                async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     618                    (ipcarg_t) packet_id, (ipcarg_t) sender);
     619       
    583620        return EOK;
    584621}
  • uspace/lib/socket/include/net_modules.h

    r24ab58b3 r14f1db0  
    7272extern void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count);
    7373
    74 /** Creates bidirectional connection with the needed module service and registers the message receiver.
    75  *  @param[in] need The needed module service.
    76  *  @param[in] arg1 The first parameter.
    77  *  @param[in] arg2 The second parameter.
    78  *  @param[in] arg3 The third parameter.
    79  *  @param[in] client_receiver The message receiver.
    80  *  @returns The phone of the needed service.
    81  *  @returns Other error codes as defined for the ipc_connect_to_me() function.
    82  */
    83 extern int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver);
    84 
    85 /** Creates bidirectional connection with the needed module service and registers the message receiver.
    86  *  @param[in] need The needed module service.
    87  *  @param[in] arg1 The first parameter.
    88  *  @param[in] arg2 The second parameter.
    89  *  @param[in] arg3 The third parameter.
    90  *  @param[in] client_receiver The message receiver.
    91  *  @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
    92  *  @returns The phone of the needed service.
    93  *  @returns ETIMEOUT if the connection timeouted.
    94  *  @returns Other error codes as defined for the ipc_connect_to_me() function.
    95  */
    96 extern int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout);
     74extern int bind_service(services_t, ipcarg_t, ipcarg_t, ipcarg_t,
     75    async_client_conn_t);
     76extern int bind_service_timeout(services_t, ipcarg_t, ipcarg_t, ipcarg_t,
     77    async_client_conn_t, suseconds_t);
    9778
    9879/** Connects to the needed module.
  • uspace/lib/socket/include/packet/packet_client.h

    r24ab58b3 r14f1db0  
    4545#define __NET_PACKET_CLIENT_H__
    4646
    47 #include "packet.h"
     47#include <packet/packet.h>
    4848
    4949/** @name Packet client interface
     
    172172 *  @returns Other error codes as defined for the packet_return() function.
    173173 */
    174 extern int packet_translate(int phone, packet_ref packet, packet_id_t packet_id);
     174extern int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id);
    175175
    176176/** Obtains the packet of the given dimensions.
     
    184184 *  @returns NULL on error.
    185185 */
    186 extern packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix);
     186extern packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix);
    187187
    188188/** Obtains the packet of the given content size.
     
    193193 *  @returns NULL on error.
    194194 */
    195 extern packet_t packet_get_1(int phone, size_t content);
     195extern packet_t packet_get_1_local(int phone, size_t content);
    196196
    197197/** Releases the packet queue.
     
    202202 *  @param[in] packet_id The packet identifier.
    203203 */
    204 extern void pq_release(int phone, packet_id_t packet_id);
     204extern void pq_release_local(int phone, packet_id_t packet_id);
    205205
    206206/** Returns the packet copy.
  • uspace/lib/socket/packet/packet_client.c

    r24ab58b3 r14f1db0  
    164164        }
    165165        // get a new packet
    166         copy = packet_get_4(phone, PACKET_DATA_LENGTH(packet), PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix, PACKET_MIN_SUFFIX(packet));
     166        copy = packet_get_4_local(phone, PACKET_DATA_LENGTH(packet), PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix, PACKET_MIN_SUFFIX(packet));
    167167        if(! copy){
    168168                return NULL;
     
    178178                return copy;
    179179        }else{
    180                 pq_release(phone, copy->packet_id);
     180                pq_release_local(phone, copy->packet_id);
    181181                return NULL;
    182182        }
  • uspace/lib/socket/packet/packet_server.c

    r24ab58b3 r14f1db0  
    9797};
    9898
    99 int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){
    100         if(! packet){
     99int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id)
     100{
     101        if (!packet)
    101102                return EINVAL;
    102         }
     103       
    103104        *packet = pm_find(packet_id);
    104105        return (*packet) ? EOK : ENOENT;
     
    161162}
    162163
    163 /** Returns the packet of dimensions at least as given.
    164  *  Tries to reuse free packets first.
    165  *  Creates a&nbsp;new packet aligned to the memory page size if none available.
    166  *  Locks the global data during its processing.
    167  *  @param[in] addr_len The source and destination addresses maximal length in bytes.
    168  *  @param[in] max_prefix The maximal prefix length in bytes.
    169  *  @param[in] max_content The maximal content length in bytes.
    170  *  @param[in] max_suffix The maximal suffix length in bytes.
    171  *  @returns The packet of dimensions at least as given.
    172  *  @returns NULL if there is not enough memory left.
    173  */
    174 static packet_t packet_get(size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix){
    175         int index;
     164/** Return the packet of dimensions at least as given.
     165 *
     166 * Try to reuse free packets first.
     167 * Create a new packet aligned to the memory page size if none available.
     168 * Lock the global data during its processing.
     169 *
     170 * @param[in] addr_len    The source and destination addresses
     171 *                        maximal length in bytes.
     172 * @param[in] max_prefix  The maximal prefix length in bytes.
     173 * @param[in] max_content The maximal content length in bytes.
     174 * @param[in] max_suffix  The maximal suffix length in bytes.
     175 *
     176 * @return The packet of dimensions at least as given.
     177 * @return NULL if there is not enough memory left.
     178 *
     179 */
     180static packet_t packet_get_local(size_t addr_len, size_t max_prefix,
     181    size_t max_content, size_t max_suffix)
     182{
     183        size_t length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len + max_prefix
     184            + max_content + max_suffix, PAGE_SIZE);
     185       
     186        fibril_mutex_lock(&ps_globals.lock);
     187       
    176188        packet_t packet;
    177         size_t length;
    178 
    179         length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len + max_prefix + max_content + max_suffix, PAGE_SIZE);
    180         fibril_mutex_lock(&ps_globals.lock);
    181         for(index = 0; index < FREE_QUEUES_COUNT - 1; ++ index){
    182                 if(length <= ps_globals.sizes[index]){
     189        unsigned int index;
     190       
     191        for (index = 0; index < FREE_QUEUES_COUNT - 1; index++) {
     192                if (length <= ps_globals.sizes[index]) {
    183193                        packet = ps_globals.free[index];
    184                         while(packet_is_valid(packet) && (packet->length < length)){
     194                       
     195                        while (packet_is_valid(packet) && (packet->length < length))
    185196                                packet = pm_find(packet->next);
    186                         }
    187                         if(packet_is_valid(packet)){
    188                                 if(packet == ps_globals.free[index]){
     197                       
     198                        if (packet_is_valid(packet)) {
     199                                if (packet == ps_globals.free[index])
    189200                                        ps_globals.free[index] = pq_detach(packet);
    190                                 }else{
     201                                else
    191202                                        pq_detach(packet);
    192                                 }
    193                                 packet_init(packet, addr_len, max_prefix, max_content, max_suffix);
     203                               
     204                                packet_init(packet, addr_len, max_prefix, max_content,
     205                                    max_suffix);
    194206                                fibril_mutex_unlock(&ps_globals.lock);
    195                                 // remove debug dump
    196 //                              printf("packet %d got\n", packet->packet_id);
     207                               
    197208                                return packet;
    198209                        }
    199210                }
    200211        }
    201         packet = packet_create(length, addr_len, max_prefix, max_content, max_suffix);
     212       
     213        packet = packet_create(length, addr_len, max_prefix, max_content,
     214            max_suffix);
     215       
    202216        fibril_mutex_unlock(&ps_globals.lock);
    203         // remove debug dump
    204 //      printf("packet %d created\n", packet->packet_id);
     217       
    205218        return packet;
    206219}
    207220
    208 packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix){
    209         return packet_get(addr_len, max_prefix, max_content, max_suffix);
    210 }
    211 
    212 packet_t packet_get_1(int phone, size_t content){
    213         return packet_get(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content, DEFAULT_SUFFIX);
    214 }
    215 
    216 /** Releases the packet and returns it to the appropriate free packet queue.
     221packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len,
     222    size_t max_prefix, size_t max_suffix)
     223{
     224        return packet_get_local(addr_len, max_prefix, max_content, max_suffix);
     225}
     226
     227packet_t packet_get_1_local(int phone, size_t content)
     228{
     229        return packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content,
     230            DEFAULT_SUFFIX);
     231}
     232
     233/** Release the packet and returns it to the appropriate free packet queue.
     234 *
    217235 *  Should be used only when the global data are locked.
     236 *
    218237 *  @param[in] packet The packet to be released.
     238 *
    219239 */
    220240static void packet_release(packet_t packet){
     
    247267}
    248268
    249 void pq_release(int phone, packet_id_t packet_id){
     269void pq_release_local(int phone, packet_id_t packet_id)
     270{
    250271        (void) packet_release_wrapper(packet_id);
    251272}
     
    281302                        return EOK;
    282303                case NET_PACKET_CREATE_1:
    283                         packet = packet_get(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX);
     304                        packet = packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX);
    284305                        if(! packet){
    285306                                return ENOMEM;
     
    290311                        return EOK;
    291312                case NET_PACKET_CREATE_4:
    292                         packet = packet_get(((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(call)) ? IPC_GET_ADDR_LEN(call) : DEFAULT_ADDR_LEN), DEFAULT_PREFIX + IPC_GET_PREFIX(call), IPC_GET_CONTENT(call), DEFAULT_SUFFIX + IPC_GET_SUFFIX(call));
     313                        packet = packet_get_local(((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(call)) ? IPC_GET_ADDR_LEN(call) : DEFAULT_ADDR_LEN), DEFAULT_PREFIX + IPC_GET_PREFIX(call), IPC_GET_CONTENT(call), DEFAULT_SUFFIX + IPC_GET_SUFFIX(call));
    293314                        if(! packet){
    294315                                return ENOMEM;
Note: See TracChangeset for help on using the changeset viewer.