Changeset 4f64a523 in mainline for uspace/lib/c/generic/iplink_srv.c


Ignore:
Timestamp:
2012-02-12T19:36:32Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
df15e5f
Parents:
1493811
Message:

Need to limit iplink to a single client connection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/iplink_srv.c

    r1493811 r4f64a523  
    4141#include <inet/iplink_srv.h>
    4242
    43 static void iplink_get_mtu_srv(iplink_conn_t *conn, ipc_callid_t callid,
     43static void iplink_get_mtu_srv(iplink_srv_t *srv, ipc_callid_t callid,
    4444    ipc_call_t *call)
    4545{
     
    4747        size_t mtu;
    4848
    49         rc = conn->srv->ops->get_mtu(conn, &mtu);
     49        rc = srv->ops->get_mtu(srv, &mtu);
    5050        async_answer_1(callid, rc, mtu);
    5151}
    5252
    53 static void iplink_send_srv(iplink_conn_t *conn, ipc_callid_t callid,
     53static void iplink_send_srv(iplink_srv_t *srv, ipc_callid_t callid,
    5454    ipc_call_t *call)
    5555{
     
    6666        }
    6767
    68         rc = conn->srv->ops->send(conn, &sdu);
     68        rc = srv->ops->send(srv, &sdu);
    6969        free(sdu.data);
    7070        async_answer_0(callid, rc);
     71}
     72
     73void iplink_srv_init(iplink_srv_t *srv)
     74{
     75        fibril_mutex_initialize(&srv->lock);
     76        srv->connected = false;
     77        srv->ops = NULL;
     78        srv->arg = NULL;
     79        srv->client_sess = NULL;
    7180}
    7281
     
    7483{
    7584        iplink_srv_t *srv = (iplink_srv_t *)arg;
    76         iplink_conn_t conn;
    7785        int rc;
     86
     87        fibril_mutex_lock(&srv->lock);
     88        if (srv->connected) {
     89                fibril_mutex_unlock(&srv->lock);
     90                async_answer_0(iid, EBUSY);
     91                return EBUSY;
     92        }
     93
     94        srv->connected = true;
     95        fibril_mutex_unlock(&srv->lock);
    7896
    7997        /* Accept the connection */
     
    84102                return ENOMEM;
    85103
    86         conn.srv = srv;
    87         conn.client_sess = sess;
     104        srv->client_sess = sess;
    88105
    89         rc = srv->ops->open(&conn);
     106        rc = srv->ops->open(srv);
    90107        if (rc != EOK)
    91108                return rc;
     
    104121                switch (method) {
    105122                case IPLINK_GET_MTU:
    106                         iplink_get_mtu_srv(&conn, callid, &call);
     123                        iplink_get_mtu_srv(srv, callid, &call);
    107124                        break;
    108125                case IPLINK_SEND:
    109                         iplink_send_srv(&conn, callid, &call);
     126                        iplink_send_srv(srv, callid, &call);
    110127                        break;
    111128                default:
     
    114131        }
    115132
    116         return srv->ops->close(&conn);
     133        return srv->ops->close(srv);
    117134}
    118135
    119 int iplink_ev_recv(iplink_conn_t *conn, iplink_srv_sdu_t *sdu)
     136int iplink_ev_recv(iplink_srv_t *srv, iplink_srv_sdu_t *sdu)
    120137{
    121         async_exch_t *exch = async_exchange_begin(conn->client_sess);
     138        if (srv->client_sess == NULL)
     139                return EIO;
     140
     141        async_exch_t *exch = async_exchange_begin(srv->client_sess);
    122142
    123143        ipc_call_t answer;
Note: See TracChangeset for help on using the changeset viewer.