Changes in uspace/lib/c/generic/inet/udp.c [1f2b07a:f9b2cb4c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/inet/udp.c
r1f2b07a rf9b2cb4c 43 43 static void udp_cb_conn(ipc_callid_t, ipc_call_t *, void *); 44 44 45 /** Create callback connection from UDP service. 46 * 47 * @param udp UDP service 48 * @return EOK on success or negative error code 49 */ 45 50 static int udp_callback_create(udp_t *udp) 46 51 { … … 48 53 49 54 aid_t req = async_send_0(exch, UDP_CALLBACK_CREATE, NULL); 50 int rc = async_connect_to_me(exch, 0, 0, 0, udp_cb_conn, udp); 55 56 port_id_t port; 57 int rc = async_create_callback_port(exch, INTERFACE_UDP_CB, 0, 0, 58 udp_cb_conn, udp, &port); 59 51 60 async_exchange_end(exch); 52 61 … … 60 69 } 61 70 71 /** Create UDP client instance. 72 * 73 * @param rudp Place to store pointer to new UDP client 74 * @return EOK on success, ENOMEM if out of memory, EIO if service 75 * cannot be contacted 76 */ 62 77 int udp_create(udp_t **rudp) 63 78 { … … 83 98 } 84 99 85 udp->sess = loc_service_connect( EXCHANGE_SERIALIZE, udp_svcid,100 udp->sess = loc_service_connect(udp_svcid, INTERFACE_UDP, 86 101 IPC_FLAG_BLOCKING); 87 102 if (udp->sess == NULL) { … … 103 118 } 104 119 120 /** Destroy UDP client instance. 121 * 122 * @param udp UDP client 123 */ 105 124 void udp_destroy(udp_t *udp) 106 125 { … … 118 137 } 119 138 120 int udp_assoc_create(udp_t *udp, inet_ep2_t *ep2, udp_cb_t *cb, void *arg, 139 /** Create new UDP association. 140 * 141 * Create a UDP association that allows sending and receiving messages. 142 * 143 * @a epp may specify remote address and port, in which case only messages 144 * from that remote endpoint will be received. Also, that remote endpoint 145 * is used as default when @c NULL is passed as destination to 146 * udp_assoc_send_msg. 147 * 148 * @a epp may specify a local link or address. If it does not, the association 149 * will listen on all local links/addresses. If @a epp does not specify 150 * a local port number, a free dynamic port number will be allocated. 151 * 152 * The caller is informed about incoming data by invoking @a cb->recv_msg 153 * 154 * @param udp UDP client 155 * @param epp Internet endpoint pair 156 * @param cb Callbacks 157 * @param arg Argument to callbacks 158 * @param rassoc Place to store pointer to new association 159 * 160 * @return EOK on success or negative error code. 161 */ 162 int udp_assoc_create(udp_t *udp, inet_ep2_t *epp, udp_cb_t *cb, void *arg, 121 163 udp_assoc_t **rassoc) 122 164 { … … 131 173 exch = async_exchange_begin(udp->sess); 132 174 aid_t req = async_send_0(exch, UDP_ASSOC_CREATE, &answer); 133 sysarg_t rc = async_data_write_start(exch, (void *)ep 2,175 sysarg_t rc = async_data_write_start(exch, (void *)epp, 134 176 sizeof(inet_ep2_t)); 135 177 async_exchange_end(exch); … … 161 203 } 162 204 205 /** Destroy UDP association. 206 * 207 * Destroy UDP association. The caller should destroy all associations 208 * he created before destroying the UDP client and before terminating. 209 * 210 * @param assoc UDP association 211 */ 163 212 void udp_assoc_destroy(udp_assoc_t *assoc) 164 213 { … … 178 227 } 179 228 229 /** Send message via UDP association. 230 * 231 * @param assoc Association 232 * @param dest Destination endpoint or @c NULL to use association's remote ep. 233 * @param data Message data 234 * @param bytes Message size in bytes 235 * 236 * @return EOK on success or negative error code 237 */ 180 238 int udp_assoc_send_msg(udp_assoc_t *assoc, inet_ep_t *dest, void *data, 181 239 size_t bytes) … … 211 269 } 212 270 271 /** Get the user/callback argument for an association. 272 * 273 * @param assoc UDP association 274 * @return User argument associated with association 275 */ 213 276 void *udp_assoc_userptr(udp_assoc_t *assoc) 214 277 { … … 216 279 } 217 280 281 /** Get size of received message in bytes. 282 * 283 * Assuming jumbo messages can be received, the caller first needs to determine 284 * the size of the received message by calling this function, then they can 285 * read the message piece-wise using udp_rmsg_read(). 286 * 287 * @param rmsg Received message 288 * @return Size of received message in bytes 289 */ 218 290 size_t udp_rmsg_size(udp_rmsg_t *rmsg) 219 291 { … … 221 293 } 222 294 295 /** Read part of received message. 296 * 297 * @param rmsg Received message 298 * @param off Start offset 299 * @param buf Buffer for storing data 300 * @param bsize Buffer size 301 * 302 * @return EOK on success or negative error code. 303 */ 223 304 int udp_rmsg_read(udp_rmsg_t *rmsg, size_t off, void *buf, size_t bsize) 224 305 { … … 245 326 } 246 327 328 /** Get remote endpoint of received message. 329 * 330 * Place the remote endpoint (the one from which the message was supposedly 331 * sent) to @a ep. 332 * 333 * @param rmsg Received message 334 * @param ep Place to store remote endpoint 335 */ 247 336 void udp_rmsg_remote_ep(udp_rmsg_t *rmsg, inet_ep_t *ep) 248 337 { … … 250 339 } 251 340 341 /** Get type of received ICMP error message. 342 * 343 * @param rerr Received error message 344 * @return Error message type 345 */ 252 346 uint8_t udp_rerr_type(udp_rerr_t *rerr) 253 347 { … … 255 349 } 256 350 351 /** Get code of received ICMP error message. 352 * 353 * @param rerr Received error message 354 * @return Error message code 355 */ 257 356 uint8_t udp_rerr_code(udp_rerr_t *rerr) 258 357 { … … 260 359 } 261 360 361 /** Get information about the next received message from UDP service. 362 * 363 * @param udp UDP client 364 * @param rmsg Place to store message information 365 * 366 * @return EOK on success or negative error code 367 */ 262 368 static int udp_rmsg_info(udp_t *udp, udp_rmsg_t *rmsg) 263 369 { … … 288 394 } 289 395 396 /** Discard next received message in UDP service. 397 * 398 * @param udp UDP client 399 * @return EOK on success or negative error code 400 */ 290 401 static int udp_rmsg_discard(udp_t *udp) 291 402 { … … 299 410 } 300 411 412 /** Get association based on its ID. 413 * 414 * @param udp UDP client 415 * @param id Association ID 416 * @param rassoc Place to store pointer to association 417 * 418 * @return EOK on success, EINVAL if no association with the given ID exists 419 */ 301 420 static int udp_assoc_get(udp_t *udp, sysarg_t id, udp_assoc_t **rassoc) 302 421 { … … 311 430 } 312 431 432 /** Handle 'data' event, i.e. some message(s) arrived. 433 * 434 * For each received message, get information about it, call @c recv_msg 435 * callback and discard it. 436 * 437 * @param udp UDP client 438 * @param iid IPC message ID 439 * @param icall IPC message 440 */ 313 441 static void udp_ev_data(udp_t *udp, ipc_callid_t iid, ipc_call_t *icall) 314 442 { … … 340 468 } 341 469 470 /** UDP service callback connection. 471 * 472 * @param iid Connect message ID 473 * @param icall Connect message 474 * @param arg Argument, UDP client 475 */ 342 476 static void udp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 343 477 {
Note:
See TracChangeset
for help on using the changeset viewer.