Changes in uspace/lib/net/generic/packet_remote.c [14f1db0:ffa2c8ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/generic/packet_remote.c
r14f1db0 rffa2c8ef 27 27 */ 28 28 29 /** @addtogroup packet30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * Packet client interface implementation for remote modules. 35 * @see packet_client.h 36 36 */ 37 37 38 38 #include <async.h> 39 39 #include <errno.h> 40 #include <ipc/ ipc.h>40 #include <ipc/packet.h> 41 41 #include <sys/mman.h> 42 42 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> 49 44 #include <packet_remote.h> 45 46 #include <net/packet.h> 47 #include <net/packet_header.h> 50 48 51 49 /** Obtain the packet from the packet server as the shared memory block. … … 64 62 * 65 63 */ 66 static int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size){67 ERROR_DECLARE; 68 64 static int 65 packet_return(int phone, packet_t **packet, packet_id_t packet_id, size_t size) 66 { 69 67 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) { 74 76 munmap(*packet, size); 75 77 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; 80 88 async_wait_for(message, &result); 81 89 … … 83 91 } 84 92 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 */ 108 int packet_translate_remote(int phone, packet_t **packet, packet_id_t packet_id) 109 { 110 int rc; 88 111 89 112 if (!packet) … … 91 114 92 115 *packet = pm_find(packet_id); 93 if (! (*packet)) {94 ipcarg_t size;116 if (!*packet) { 117 sysarg_t size; 95 118 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; 101 129 102 return packet_translate_remote(phone, &next, (* * packet).next);130 return packet_translate_remote(phone, &next, (*packet)->next); 103 131 } 104 132 … … 106 134 } 107 135 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 */ 149 packet_t *packet_get_4_remote(int phone, size_t max_content, size_t addr_len, 109 150 size_t max_prefix, size_t max_suffix) 110 151 { 111 ERROR_DECLARE;112 113 i pcarg_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) 118 159 return NULL; 119 160 120 161 121 packet_t packet = pm_find(packet_id);162 packet_t *packet = pm_find(packet_id); 122 163 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) 124 166 return NULL; 125 167 } … … 128 170 } 129 171 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 */ 181 packet_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) 139 190 return NULL; 140 191 141 packet_t packet = pm_find(packet_id);192 packet_t *packet = pm_find(packet_id); 142 193 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) 144 196 return NULL; 145 197 } … … 148 200 } 149 201 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 */ 150 212 void pq_release_remote(int phone, packet_id_t packet_id) 151 213 {
Note:
See TracChangeset
for help on using the changeset viewer.