Ignore:
Timestamp:
2010-11-22T15:39:53Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eddb76, aae339e9
Parents:
9a1d8ab (diff), 8cd1aa5e (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 development/ changes

File:
1 edited

Legend:

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

    r9a1d8ab r0b749a3  
    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
     
    3939#include <errno.h>
    4040#include <ipc/ipc.h>
     41#include <ipc/packet.h>
    4142#include <sys/mman.h>
    4243
    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>
     44#include <packet_client.h>
    4945#include <packet_remote.h>
     46
     47#include <net/packet.h>
     48#include <net/packet_header.h>
    5049
    5150/** Obtain the packet from the packet server as the shared memory block.
     
    6463 *
    6564 */
    66 static int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size){
    67         ERROR_DECLARE;
    68        
     65static int
     66packet_return(int phone, packet_t **packet, packet_id_t packet_id, size_t size)
     67{
    6968        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))) {
     69        aid_t message;
     70        int rc;
     71       
     72        message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
     73
     74        *packet = (packet_t *) as_get_mappable_page(size);
     75        rc = async_share_in_start_0_0(phone, *packet, size);
     76        if (rc != EOK) {
    7477                munmap(*packet, size);
    7578                async_wait_for(message, NULL);
    76                 return ERROR_CODE;
     79                return rc;
     80        }
     81        rc = pm_add(*packet);
     82        if (rc != EOK) {
     83                munmap(*packet, size);
     84                async_wait_for(message, NULL);
     85                return rc;
    7786        }
    7887       
     
    8392}
    8493
    85 int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id)
    86 {
    87         ERROR_DECLARE;
     94/** Translates the packet identifier to the packet reference.
     95 *
     96 * Tries to find mapping first.
     97 * Contacts the packet server to share the packet if the mapping is not present.
     98 *
     99 * @param[in] phone     The packet server module phone.
     100 * @param[out] packet   The packet reference.
     101 * @param[in] packet_id The packet identifier.
     102 * @return              EOK on success.
     103 * @return              EINVAL if the packet parameter is NULL.
     104 * @return              Other error codes as defined for the NET_PACKET_GET_SIZE
     105 *                      message.
     106 * @return              Other error codes as defined for the packet_return()
     107 *                      function.
     108 */
     109int packet_translate_remote(int phone, packet_t **packet, packet_id_t packet_id)
     110{
     111        int rc;
    88112       
    89113        if (!packet)
     
    91115       
    92116        *packet = pm_find(packet_id);
    93         if (!(*packet)) {
     117        if (!*packet) {
    94118                ipcarg_t size;
    95119               
    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;
     120                rc = async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id,
     121                    &size);
     122                if (rc != EOK)
     123                        return rc;
     124                rc = packet_return(phone, packet, packet_id, size);
     125                if (rc != EOK)
     126                        return rc;
     127        }
     128        if ((*packet)->next) {
     129                packet_t *next;
    101130               
    102                 return packet_translate_remote(phone, &next, (** packet).next);
     131                return packet_translate_remote(phone, &next, (*packet)->next);
    103132        }
    104133       
     
    106135}
    107136
    108 packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len,
     137/** Obtains the packet of the given dimensions.
     138 *
     139 * Contacts the packet server to return the appropriate packet.
     140 *
     141 * @param[in] phone     The packet server module phone.
     142 * @param[in] addr_len  The source and destination addresses maximal length in
     143 *                      bytes.
     144 * @param[in] max_prefix The maximal prefix length in bytes.
     145 * @param[in] max_content The maximal content length in bytes.
     146 * @param[in] max_suffix The maximal suffix length in bytes.
     147 * @return              The packet reference.
     148 * @return              NULL on error.
     149 */
     150packet_t *packet_get_4_remote(int phone, size_t max_content, size_t addr_len,
    109151    size_t max_prefix, size_t max_suffix)
    110152{
    111         ERROR_DECLARE;
    112        
    113153        ipcarg_t packet_id;
    114154        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)))
     155        int rc;
     156       
     157        rc = async_req_4_2(phone, NET_PACKET_CREATE_4, max_content, addr_len,
     158            max_prefix, max_suffix, &packet_id, &size);
     159        if (rc != EOK)
    118160                return NULL;
    119161       
    120162       
    121         packet_t packet = pm_find(packet_id);
     163        packet_t *packet = pm_find(packet_id);
    122164        if (!packet) {
    123                 if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size)))
     165                rc = packet_return(phone, &packet, packet_id, size);
     166                if (rc != EOK)
    124167                        return NULL;
    125168        }
     
    128171}
    129172
    130 packet_t packet_get_1_remote(int phone, size_t content)
    131 {
    132         ERROR_DECLARE;
    133        
     173/** Obtains the packet of the given content size.
     174 *
     175 * Contacts the packet server to return the appropriate packet.
     176 *
     177 * @param[in] phone     The packet server module phone.
     178 * @param[in] content   The maximal content length in bytes.
     179 * @return              The packet reference.
     180 * @return              NULL on error.
     181 */
     182packet_t *packet_get_1_remote(int phone, size_t content)
     183{
    134184        ipcarg_t packet_id;
    135185        ipcarg_t size;
    136        
    137         if (ERROR_OCCURRED(async_req_1_2(phone, NET_PACKET_CREATE_1, content,
    138             &packet_id, &size)))
     186        int rc;
     187       
     188        rc = async_req_1_2(phone, NET_PACKET_CREATE_1, content, &packet_id,
     189            &size);
     190        if (rc != EOK)
    139191                return NULL;
    140192       
    141         packet_t packet = pm_find(packet_id);
     193        packet_t *packet = pm_find(packet_id);
    142194        if (!packet) {
    143                 if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size)))
     195                rc = packet_return(phone, &packet, packet_id, size);
     196                if (rc != EOK)
    144197                        return NULL;
    145198        }
     
    148201}
    149202
     203/** Releases the packet queue.
     204 *
     205 * All packets in the queue are marked as free for use.
     206 * The packet queue may be one packet only.
     207 * The module should not use the packets after this point until they are
     208 * received or obtained again.
     209 *
     210 * @param[in] phone     The packet server module phone.
     211 * @param[in] packet_id The packet identifier.
     212 */
    150213void pq_release_remote(int phone, packet_id_t packet_id)
    151214{
Note: See TracChangeset for help on using the changeset viewer.