Changeset b10460a in mainline for uspace/lib/c/generic/inet/udp.c
- Timestamp:
- 2015-08-07T21:39:00Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b688fd8
- Parents:
- 6accc5cf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/inet/udp.c
r6accc5cf rb10460a 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 { … … 60 65 } 61 66 67 /** Create UDP client instance. 68 * 69 * @param rudp Place to store pointer to new UDP client 70 * @return EOK on success, ENOMEM if out of memory, EIO if service 71 * cannot be contacted 72 */ 62 73 int udp_create(udp_t **rudp) 63 74 { … … 103 114 } 104 115 116 /** Destroy UDP client instance. 117 * 118 * @param udp UDP client 119 */ 105 120 void udp_destroy(udp_t *udp) 106 121 { … … 118 133 } 119 134 120 int udp_assoc_create(udp_t *udp, inet_ep2_t *ep2, udp_cb_t *cb, void *arg, 135 /** Create new UDP association. 136 * 137 * Create a UDP association that allows sending and receiving messages. 138 * 139 * @a epp may specify remote address and port, in which case only messages 140 * from that remote endpoint will be received. Also, that remote endpoint 141 * is used as default when @c NULL is passed as destination to 142 * udp_assoc_send_msg. 143 * 144 * @a epp may specify a local link or address. If it does not, the association 145 * will listen on all local links/addresses. If @a epp does not specify 146 * a local port number, a free dynamic port number will be allocated. 147 * 148 * The caller is informed about incoming data by invoking @a cb->recv_msg 149 * 150 * @param udp UDP client 151 * @param epp Internet endpoint pair 152 * @param cb Callbacks 153 * @param arg Argument to callbacks 154 * @param rassoc Place to store pointer to new association 155 * 156 * @return EOK on success or negative error code. 157 */ 158 int udp_assoc_create(udp_t *udp, inet_ep2_t *epp, udp_cb_t *cb, void *arg, 121 159 udp_assoc_t **rassoc) 122 160 { … … 131 169 exch = async_exchange_begin(udp->sess); 132 170 aid_t req = async_send_0(exch, UDP_ASSOC_CREATE, &answer); 133 sysarg_t rc = async_data_write_start(exch, (void *)ep 2,171 sysarg_t rc = async_data_write_start(exch, (void *)epp, 134 172 sizeof(inet_ep2_t)); 135 173 async_exchange_end(exch); … … 161 199 } 162 200 201 /** Destroy UDP association. 202 * 203 * Destroy UDP association. The caller should destroy all associations 204 * he created before destroying the UDP client and before terminating. 205 * 206 * @param assoc UDP association 207 */ 163 208 void udp_assoc_destroy(udp_assoc_t *assoc) 164 209 { … … 178 223 } 179 224 225 /** Send message via UDP association. 226 * 227 * @param assoc Association 228 * @param dest Destination endpoint or @c NULL to use association's remote ep. 229 * @param data Message data 230 * @param bytes Message size in bytes 231 * 232 * @return EOK on success or negative error code 233 */ 180 234 int udp_assoc_send_msg(udp_assoc_t *assoc, inet_ep_t *dest, void *data, 181 235 size_t bytes) … … 211 265 } 212 266 267 /** Get the user/callback argument for an association. 268 * 269 * @param assoc UDP association 270 * @return User argument associated with association 271 */ 213 272 void *udp_assoc_userptr(udp_assoc_t *assoc) 214 273 { … … 216 275 } 217 276 277 /** Get size of received message in bytes. 278 * 279 * Assuming jumbo messages can be received, the caller first needs to determine 280 * the size of the received message by calling this function, then they can 281 * read the message piece-wise using udp_rmsg_read(). 282 * 283 * @param rmsg Received message 284 * @return Size of received message in bytes 285 */ 218 286 size_t udp_rmsg_size(udp_rmsg_t *rmsg) 219 287 { … … 221 289 } 222 290 291 /** Read part of received message. 292 * 293 * @param rmsg Received message 294 * @param off Start offset 295 * @param buf Buffer for storing data 296 * @param bsize Buffer size 297 * 298 * @return EOK on success or negative error code. 299 */ 223 300 int udp_rmsg_read(udp_rmsg_t *rmsg, size_t off, void *buf, size_t bsize) 224 301 { … … 245 322 } 246 323 324 /** Get remote endpoint of received message. 325 * 326 * Place the remote endpoint (the one from which the message was supposedly 327 * sent) to @a ep. 328 * 329 * @param rmsg Received message 330 * @param ep Place to store remote endpoint 331 */ 247 332 void udp_rmsg_remote_ep(udp_rmsg_t *rmsg, inet_ep_t *ep) 248 333 { … … 250 335 } 251 336 337 /** Get type of received ICMP error message. 338 * 339 * @param rerr Received error message 340 * @return Error message type 341 */ 252 342 uint8_t udp_rerr_type(udp_rerr_t *rerr) 253 343 { … … 255 345 } 256 346 347 /** Get code of received ICMP error message. 348 * 349 * @param rerr Received error message 350 * @return Error message code 351 */ 257 352 uint8_t udp_rerr_code(udp_rerr_t *rerr) 258 353 { … … 260 355 } 261 356 357 /** Get information about the next received message from UDP service. 358 * 359 * @param udp UDP client 360 * @param rmsg Place to store message information 361 * 362 * @return EOK on success or negative error code 363 */ 262 364 static int udp_rmsg_info(udp_t *udp, udp_rmsg_t *rmsg) 263 365 { … … 288 390 } 289 391 392 /** Discard next received message in UDP service. 393 * 394 * @param udp UDP client 395 * @return EOK on success or negative error code 396 */ 290 397 static int udp_rmsg_discard(udp_t *udp) 291 398 { … … 299 406 } 300 407 408 /** Get association based on its ID. 409 * 410 * @param udp UDP client 411 * @param id Association ID 412 * @param rassoc Place to store pointer to association 413 * 414 * @return EOK on success, EINVAL if no association with the given ID exists 415 */ 301 416 static int udp_assoc_get(udp_t *udp, sysarg_t id, udp_assoc_t **rassoc) 302 417 { … … 311 426 } 312 427 428 /** Handle 'data' event, i.e. some message(s) arrived. 429 * 430 * For each received message, get information about it, call @c recv_msg 431 * callback and discard it. 432 * 433 * @param udp UDP client 434 * @param iid IPC message ID 435 * @param icall IPC message 436 */ 313 437 static void udp_ev_data(udp_t *udp, ipc_callid_t iid, ipc_call_t *icall) 314 438 { … … 340 464 } 341 465 466 /** UDP service callback connection. 467 * 468 * @param iid Connect message ID 469 * @param icall Connect message 470 * @param arg Argument, UDP client 471 */ 342 472 static void udp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 343 473 {
Note:
See TracChangeset
for help on using the changeset viewer.