Ignore:
File:
1 edited

Legend:

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

    rf9b2cb4c r1f2b07a  
    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  */
    5045static int udp_callback_create(udp_t *udp)
    5146{
     
    5348
    5449        aid_t req = async_send_0(exch, UDP_CALLBACK_CREATE, NULL);
    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        
     50        int rc = async_connect_to_me(exch, 0, 0, 0, udp_cb_conn, udp);
    6051        async_exchange_end(exch);
    6152
     
    6960}
    7061
    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  */
    7762int udp_create(udp_t **rudp)
    7863{
     
    9883        }
    9984
    100         udp->sess = loc_service_connect(udp_svcid, INTERFACE_UDP,
     85        udp->sess = loc_service_connect(EXCHANGE_SERIALIZE, udp_svcid,
    10186            IPC_FLAG_BLOCKING);
    10287        if (udp->sess == NULL) {
     
    118103}
    119104
    120 /** Destroy UDP client instance.
    121  *
    122  * @param udp UDP client
    123  */
    124105void udp_destroy(udp_t *udp)
    125106{
     
    137118}
    138119
    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,
     120int udp_assoc_create(udp_t *udp, inet_ep2_t *ep2, udp_cb_t *cb, void *arg,
    163121    udp_assoc_t **rassoc)
    164122{
     
    173131        exch = async_exchange_begin(udp->sess);
    174132        aid_t req = async_send_0(exch, UDP_ASSOC_CREATE, &answer);
    175         sysarg_t rc = async_data_write_start(exch, (void *)epp,
     133        sysarg_t rc = async_data_write_start(exch, (void *)ep2,
    176134            sizeof(inet_ep2_t));
    177135        async_exchange_end(exch);
     
    203161}
    204162
    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  */
    212163void udp_assoc_destroy(udp_assoc_t *assoc)
    213164{
     
    227178}
    228179
    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  */
    238180int udp_assoc_send_msg(udp_assoc_t *assoc, inet_ep_t *dest, void *data,
    239181    size_t bytes)
     
    269211}
    270212
    271 /** Get the user/callback argument for an association.
    272  *
    273  * @param assoc UDP association
    274  * @return User argument associated with association
    275  */
    276213void *udp_assoc_userptr(udp_assoc_t *assoc)
    277214{
     
    279216}
    280217
    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  */
    290218size_t udp_rmsg_size(udp_rmsg_t *rmsg)
    291219{
     
    293221}
    294222
    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  */
    304223int udp_rmsg_read(udp_rmsg_t *rmsg, size_t off, void *buf, size_t bsize)
    305224{
     
    326245}
    327246
    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  */
    336247void udp_rmsg_remote_ep(udp_rmsg_t *rmsg, inet_ep_t *ep)
    337248{
     
    339250}
    340251
    341 /** Get type of received ICMP error message.
    342  *
    343  * @param rerr Received error message
    344  * @return Error message type
    345  */
    346252uint8_t udp_rerr_type(udp_rerr_t *rerr)
    347253{
     
    349255}
    350256
    351 /** Get code of received ICMP error message.
    352  *
    353  * @param rerr Received error message
    354  * @return Error message code
    355  */
    356257uint8_t udp_rerr_code(udp_rerr_t *rerr)
    357258{
     
    359260}
    360261
    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  */
    368262static int udp_rmsg_info(udp_t *udp, udp_rmsg_t *rmsg)
    369263{
     
    394288}
    395289
    396 /** Discard next received message in UDP service.
    397  *
    398  * @param udp UDP client
    399  * @return EOK on success or negative error code
    400  */
    401290static int udp_rmsg_discard(udp_t *udp)
    402291{
     
    410299}
    411300
    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  */
    420301static int udp_assoc_get(udp_t *udp, sysarg_t id, udp_assoc_t **rassoc)
    421302{
     
    430311}
    431312
    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  */
    441313static void udp_ev_data(udp_t *udp, ipc_callid_t iid, ipc_call_t *icall)
    442314{
     
    468340}
    469341
    470 /** UDP service callback connection.
    471  *
    472  * @param iid Connect message ID
    473  * @param icall Connect message
    474  * @param arg Argument, UDP client
    475  */
    476342static void udp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    477343{
Note: See TracChangeset for help on using the changeset viewer.