Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/generic/packet_remote.c

    r14f1db0 rffa2c8ef  
    2727 */
    2828
    29 /** @addtogroup packet
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Packet client interface implementation for remote modules.
    35  *  @see packet_client.h
     34 * Packet client interface implementation for remote modules.
     35 * @see packet_client.h
    3636 */
    3737
    3838#include <async.h>
    3939#include <errno.h>
    40 #include <ipc/ipc.h>
     40#include <ipc/packet.h>
    4141#include <sys/mman.h>
    4242
    43 #include <net_err.h>
    44 #include <net_messages.h>
    45 #include <packet/packet.h>
    46 #include <packet/packet_client.h>
    47 #include <packet/packet_header.h>
    48 #include <packet/packet_messages.h>
     43#include <packet_client.h>
    4944#include <packet_remote.h>
     45
     46#include <net/packet.h>
     47#include <net/packet_header.h>
    5048
    5149/** Obtain the packet from the packet server as the shared memory block.
     
    6462 *
    6563 */
    66 static int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size){
    67         ERROR_DECLARE;
    68        
     64static int
     65packet_return(int phone, packet_t **packet, packet_id_t packet_id, size_t size)
     66{
    6967        ipc_call_t answer;
    70         aid_t message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
    71         *packet = (packet_t) as_get_mappable_page(size);
    72         if (ERROR_OCCURRED(async_share_in_start_0_0(phone, *packet, size))
    73             || ERROR_OCCURRED(pm_add(*packet))) {
     68        aid_t message;
     69        int rc;
     70       
     71        message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
     72
     73        *packet = (packet_t *) as_get_mappable_page(size);
     74        rc = async_share_in_start_0_0(phone, *packet, size);
     75        if (rc != EOK) {
    7476                munmap(*packet, size);
    7577                async_wait_for(message, NULL);
    76                 return ERROR_CODE;
    77         }
    78        
    79         ipcarg_t result;
     78                return rc;
     79        }
     80        rc = pm_add(*packet);
     81        if (rc != EOK) {
     82                munmap(*packet, size);
     83                async_wait_for(message, NULL);
     84                return rc;
     85        }
     86       
     87        sysarg_t result;
    8088        async_wait_for(message, &result);
    8189       
     
    8391}
    8492
    85 int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id)
    86 {
    87         ERROR_DECLARE;
     93/** Translates the packet identifier to the packet reference.
     94 *
     95 * Tries to find mapping first.
     96 * Contacts the packet server to share the packet if the mapping is not present.
     97 *
     98 * @param[in] phone     The packet server module phone.
     99 * @param[out] packet   The packet reference.
     100 * @param[in] packet_id The packet identifier.
     101 * @return              EOK on success.
     102 * @return              EINVAL if the packet parameter is NULL.
     103 * @return              Other error codes as defined for the NET_PACKET_GET_SIZE
     104 *                      message.
     105 * @return              Other error codes as defined for the packet_return()
     106 *                      function.
     107 */
     108int packet_translate_remote(int phone, packet_t **packet, packet_id_t packet_id)
     109{
     110        int rc;
    88111       
    89112        if (!packet)
     
    91114       
    92115        *packet = pm_find(packet_id);
    93         if (!(*packet)) {
    94                 ipcarg_t size;
     116        if (!*packet) {
     117                sysarg_t size;
    95118               
    96                 ERROR_PROPAGATE(async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id, &size));
    97                 ERROR_PROPAGATE(packet_return(phone, packet, packet_id, size));
    98         }
    99         if ((** packet).next) {
    100                 packet_t next;
     119                rc = async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id,
     120                    &size);
     121                if (rc != EOK)
     122                        return rc;
     123                rc = packet_return(phone, packet, packet_id, size);
     124                if (rc != EOK)
     125                        return rc;
     126        }
     127        if ((*packet)->next) {
     128                packet_t *next;
    101129               
    102                 return packet_translate_remote(phone, &next, (** packet).next);
     130                return packet_translate_remote(phone, &next, (*packet)->next);
    103131        }
    104132       
     
    106134}
    107135
    108 packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len,
     136/** Obtains the packet of the given dimensions.
     137 *
     138 * Contacts the packet server to return the appropriate packet.
     139 *
     140 * @param[in] phone     The packet server module phone.
     141 * @param[in] addr_len  The source and destination addresses maximal length in
     142 *                      bytes.
     143 * @param[in] max_prefix The maximal prefix length in bytes.
     144 * @param[in] max_content The maximal content length in bytes.
     145 * @param[in] max_suffix The maximal suffix length in bytes.
     146 * @return              The packet reference.
     147 * @return              NULL on error.
     148 */
     149packet_t *packet_get_4_remote(int phone, size_t max_content, size_t addr_len,
    109150    size_t max_prefix, size_t max_suffix)
    110151{
    111         ERROR_DECLARE;
    112        
    113         ipcarg_t packet_id;
    114         ipcarg_t size;
    115        
    116         if (ERROR_OCCURRED(async_req_4_2(phone, NET_PACKET_CREATE_4, max_content,
    117             addr_len, max_prefix, max_suffix, &packet_id, &size)))
     152        sysarg_t packet_id;
     153        sysarg_t size;
     154        int rc;
     155       
     156        rc = async_req_4_2(phone, NET_PACKET_CREATE_4, max_content, addr_len,
     157            max_prefix, max_suffix, &packet_id, &size);
     158        if (rc != EOK)
    118159                return NULL;
    119160       
    120161       
    121         packet_t packet = pm_find(packet_id);
     162        packet_t *packet = pm_find(packet_id);
    122163        if (!packet) {
    123                 if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size)))
     164                rc = packet_return(phone, &packet, packet_id, size);
     165                if (rc != EOK)
    124166                        return NULL;
    125167        }
     
    128170}
    129171
    130 packet_t packet_get_1_remote(int phone, size_t content)
    131 {
    132         ERROR_DECLARE;
    133        
    134         ipcarg_t packet_id;
    135         ipcarg_t size;
    136        
    137         if (ERROR_OCCURRED(async_req_1_2(phone, NET_PACKET_CREATE_1, content,
    138             &packet_id, &size)))
     172/** Obtains the packet of the given content size.
     173 *
     174 * Contacts the packet server to return the appropriate packet.
     175 *
     176 * @param[in] phone     The packet server module phone.
     177 * @param[in] content   The maximal content length in bytes.
     178 * @return              The packet reference.
     179 * @return              NULL on error.
     180 */
     181packet_t *packet_get_1_remote(int phone, size_t content)
     182{
     183        sysarg_t packet_id;
     184        sysarg_t size;
     185        int rc;
     186       
     187        rc = async_req_1_2(phone, NET_PACKET_CREATE_1, content, &packet_id,
     188            &size);
     189        if (rc != EOK)
    139190                return NULL;
    140191       
    141         packet_t packet = pm_find(packet_id);
     192        packet_t *packet = pm_find(packet_id);
    142193        if (!packet) {
    143                 if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size)))
     194                rc = packet_return(phone, &packet, packet_id, size);
     195                if (rc != EOK)
    144196                        return NULL;
    145197        }
     
    148200}
    149201
     202/** Releases the packet queue.
     203 *
     204 * All packets in the queue are marked as free for use.
     205 * The packet queue may be one packet only.
     206 * The module should not use the packets after this point until they are
     207 * received or obtained again.
     208 *
     209 * @param[in] phone     The packet server module phone.
     210 * @param[in] packet_id The packet identifier.
     211 */
    150212void pq_release_remote(int phone, packet_id_t packet_id)
    151213{
Note: See TracChangeset for help on using the changeset viewer.