Changeset ff381a7 in mainline for uspace/lib/c/generic/inet/udp.c


Ignore:
Timestamp:
2015-11-02T20:54:19Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d8513177
Parents:
3feeab2 (diff), 5265eea4 (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 mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/inet/udp.c

    r3feeab2 rff381a7  
    4343static void udp_cb_conn(ipc_callid_t, ipc_call_t *, void *);
    4444
     45/** Create callback connection from UDP service.
     46 *
     47 * @param udp UDP service
     48 * @return EOK on success or negative error code
     49 */
    4550static int udp_callback_create(udp_t *udp)
    4651{
     
    4853
    4954        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       
    5160        async_exchange_end(exch);
    5261
     
    6069}
    6170
     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 */
    6277int udp_create(udp_t **rudp)
    6378{
     
    8398        }
    8499
    85         udp->sess = loc_service_connect(EXCHANGE_SERIALIZE, udp_svcid,
     100        udp->sess = loc_service_connect(udp_svcid, INTERFACE_UDP,
    86101            IPC_FLAG_BLOCKING);
    87102        if (udp->sess == NULL) {
     
    103118}
    104119
     120/** Destroy UDP client instance.
     121 *
     122 * @param udp UDP client
     123 */
    105124void udp_destroy(udp_t *udp)
    106125{
     
    118137}
    119138
    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 */
     162int udp_assoc_create(udp_t *udp, inet_ep2_t *epp, udp_cb_t *cb, void *arg,
    121163    udp_assoc_t **rassoc)
    122164{
     
    131173        exch = async_exchange_begin(udp->sess);
    132174        aid_t req = async_send_0(exch, UDP_ASSOC_CREATE, &answer);
    133         sysarg_t rc = async_data_write_start(exch, (void *)ep2,
     175        sysarg_t rc = async_data_write_start(exch, (void *)epp,
    134176            sizeof(inet_ep2_t));
    135177        async_exchange_end(exch);
     
    161203}
    162204
     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 */
    163212void udp_assoc_destroy(udp_assoc_t *assoc)
    164213{
     
    178227}
    179228
     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 */
    180238int udp_assoc_send_msg(udp_assoc_t *assoc, inet_ep_t *dest, void *data,
    181239    size_t bytes)
     
    211269}
    212270
     271/** Get the user/callback argument for an association.
     272 *
     273 * @param assoc UDP association
     274 * @return User argument associated with association
     275 */
    213276void *udp_assoc_userptr(udp_assoc_t *assoc)
    214277{
     
    216279}
    217280
     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 */
    218290size_t udp_rmsg_size(udp_rmsg_t *rmsg)
    219291{
     
    221293}
    222294
     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 */
    223304int udp_rmsg_read(udp_rmsg_t *rmsg, size_t off, void *buf, size_t bsize)
    224305{
     
    245326}
    246327
     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 */
    247336void udp_rmsg_remote_ep(udp_rmsg_t *rmsg, inet_ep_t *ep)
    248337{
     
    250339}
    251340
     341/** Get type of received ICMP error message.
     342 *
     343 * @param rerr Received error message
     344 * @return Error message type
     345 */
    252346uint8_t udp_rerr_type(udp_rerr_t *rerr)
    253347{
     
    255349}
    256350
     351/** Get code of received ICMP error message.
     352 *
     353 * @param rerr Received error message
     354 * @return Error message code
     355 */
    257356uint8_t udp_rerr_code(udp_rerr_t *rerr)
    258357{
     
    260359}
    261360
     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 */
    262368static int udp_rmsg_info(udp_t *udp, udp_rmsg_t *rmsg)
    263369{
     
    288394}
    289395
     396/** Discard next received message in UDP service.
     397 *
     398 * @param udp UDP client
     399 * @return EOK on success or negative error code
     400 */
    290401static int udp_rmsg_discard(udp_t *udp)
    291402{
     
    299410}
    300411
     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 */
    301420static int udp_assoc_get(udp_t *udp, sysarg_t id, udp_assoc_t **rassoc)
    302421{
     
    311430}
    312431
     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 */
    313441static void udp_ev_data(udp_t *udp, ipc_callid_t iid, ipc_call_t *icall)
    314442{
     
    340468}
    341469
     470/** UDP service callback connection.
     471 *
     472 * @param iid Connect message ID
     473 * @param icall Connect message
     474 * @param arg Argument, UDP client
     475 */
    342476static void udp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    343477{
Note: See TracChangeset for help on using the changeset viewer.