Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/udp/service.c

    re1abc964 rfafb8e5  
    4646
    4747#include "assoc.h"
    48 #include "cassoc.h"
    4948#include "msg.h"
    5049#include "service.h"
     
    5655#define MAX_MSG_SIZE DATA_XFER_LIMIT
    5756
    58 static void udp_recv_msg_cassoc(void *, inet_ep2_t *, udp_msg_t *);
     57static void udp_cassoc_recv_msg(void *, inet_ep2_t *, udp_msg_t *);
    5958
    6059/** Callbacks to tie us to association layer */
    6160static udp_assoc_cb_t udp_cassoc_cb = {
    62         .recv_msg = udp_recv_msg_cassoc
     61        .recv_msg = udp_cassoc_recv_msg
    6362};
     63
     64/** Add message to client receive queue.
     65 *
     66 * @param cassoc Client association
     67 * @param epp    Endpoint pair on which message was received
     68 * @param msg    Message
     69 *
     70 * @return EOK on success, ENOMEM if out of memory
     71 */
     72static errno_t udp_cassoc_queue_msg(udp_cassoc_t *cassoc, inet_ep2_t *epp,
     73    udp_msg_t *msg)
     74{
     75        udp_crcv_queue_entry_t *rqe;
     76
     77        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_cassoc_queue_msg(%p, %p, %p)",
     78            cassoc, epp, msg);
     79
     80        rqe = calloc(1, sizeof(udp_crcv_queue_entry_t));
     81        if (rqe == NULL)
     82                return ENOMEM;
     83
     84        link_initialize(&rqe->link);
     85        rqe->epp = *epp;
     86        rqe->msg = msg;
     87        rqe->cassoc = cassoc;
     88
     89        list_append(&rqe->link, &cassoc->client->crcv_queue);
     90        return EOK;
     91}
    6492
    6593/** Send 'data' event to client.
     
    80108}
    81109
     110/** Create client association.
     111 *
     112 * This effectively adds an association into a client's namespace.
     113 *
     114 * @param client  Client
     115 * @param assoc   Association
     116 * @param rcassoc Place to store pointer to new client association
     117 *
     118 * @return EOK on soccess, ENOMEM if out of memory
     119 */
     120static errno_t udp_cassoc_create(udp_client_t *client, udp_assoc_t *assoc,
     121    udp_cassoc_t **rcassoc)
     122{
     123        udp_cassoc_t *cassoc;
     124        sysarg_t id;
     125
     126        cassoc = calloc(1, sizeof(udp_cassoc_t));
     127        if (cassoc == NULL)
     128                return ENOMEM;
     129
     130        /* Allocate new ID */
     131        id = 0;
     132        list_foreach (client->cassoc, lclient, udp_cassoc_t, cassoc) {
     133                if (cassoc->id >= id)
     134                        id = cassoc->id + 1;
     135        }
     136
     137        cassoc->id = id;
     138        cassoc->client = client;
     139        cassoc->assoc = assoc;
     140
     141        list_append(&cassoc->lclient, &client->cassoc);
     142        *rcassoc = cassoc;
     143        return EOK;
     144}
     145
     146/** Destroy client association.
     147 *
     148 * @param cassoc Client association
     149 */
     150static void udp_cassoc_destroy(udp_cassoc_t *cassoc)
     151{
     152        list_remove(&cassoc->lclient);
     153        free(cassoc);
     154}
     155
     156/** Get client association by ID.
     157 *
     158 * @param client  Client
     159 * @param id      Client association ID
     160 * @param rcassoc Place to store pointer to client association
     161 *
     162 * @return EOK on success, ENOENT if no client association with the given ID
     163 *         is found.
     164 */
     165static errno_t udp_cassoc_get(udp_client_t *client, sysarg_t id,
     166    udp_cassoc_t **rcassoc)
     167{
     168        list_foreach (client->cassoc, lclient, udp_cassoc_t, cassoc) {
     169                if (cassoc->id == id) {
     170                        *rcassoc = cassoc;
     171                        return EOK;
     172                }
     173        }
     174
     175        return ENOENT;
     176}
     177
    82178/** Message received on client association.
    83179 *
     
    88184 * @param msg Message
    89185 */
    90 static void udp_recv_msg_cassoc(void *arg, inet_ep2_t *epp, udp_msg_t *msg)
     186static void udp_cassoc_recv_msg(void *arg, inet_ep2_t *epp, udp_msg_t *msg)
    91187{
    92188        udp_cassoc_t *cassoc = (udp_cassoc_t *) arg;
Note: See TracChangeset for help on using the changeset viewer.