Changeset fff7ef4 in mainline for uspace/lib/c/generic/dnsr.c


Ignore:
Timestamp:
2013-04-26T07:34:42Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
48171fc4
Parents:
287d729
Message:

Make dnsr client initialization implicit (to allow for multiple consumers in the same program).

File:
1 edited

Legend:

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

    r287d729 rfff7ef4  
    3030#include <assert.h>
    3131#include <errno.h>
     32#include <fibril_synch.h>
    3233#include <inet/dnsr.h>
    3334#include <ipc/dnsr.h>
     
    3738#include <str.h>
    3839
     40static FIBRIL_MUTEX_INITIALIZE(dnsr_sess_mutex);
     41
    3942static async_sess_t *dnsr_sess = NULL;
    4043
    41 int dnsr_init(void)
     44static async_exch_t *dnsr_exchange_begin(void)
    4245{
     46        async_sess_t *sess;
    4347        service_id_t dnsr_svc;
    44         int rc;
    4548
    46         assert(dnsr_sess == NULL);
     49        fibril_mutex_lock(&dnsr_sess_mutex);
    4750
    48         rc = loc_service_get_id(SERVICE_NAME_DNSR, &dnsr_svc,
    49             IPC_FLAG_BLOCKING);
    50         if (rc != EOK)
    51                 return ENOENT;
     51        if (dnsr_sess == NULL) {
     52                (void) loc_service_get_id(SERVICE_NAME_DNSR, &dnsr_svc,
     53                    IPC_FLAG_BLOCKING);
    5254
    53         dnsr_sess = loc_service_connect(EXCHANGE_SERIALIZE, dnsr_svc,
    54             IPC_FLAG_BLOCKING);
    55         if (dnsr_sess == NULL)
    56                 return ENOENT;
     55                dnsr_sess = loc_service_connect(EXCHANGE_SERIALIZE, dnsr_svc,
     56                    IPC_FLAG_BLOCKING);
     57        }
    5758
    58         return EOK;
     59        sess = dnsr_sess;
     60        fibril_mutex_unlock(&dnsr_sess_mutex);
     61
     62        return async_exchange_begin(sess);
     63}
     64
     65static void dnsr_exchange_end(async_exch_t *exch)
     66{
     67        async_exchange_end(exch);
    5968}
    6069
    6170int dnsr_name2host(const char *name, dnsr_hostinfo_t **rinfo)
    6271{
    63         async_exch_t *exch = async_exchange_begin(dnsr_sess);
     72        async_exch_t *exch = dnsr_exchange_begin();
    6473        dnsr_hostinfo_t *info;
    6574
     
    6877        sysarg_t retval = async_data_write_start(exch, name, str_size(name));
    6978
    70         async_exchange_end(exch);
     79        dnsr_exchange_end(exch);
    7180
    7281        if (retval != EOK) {
     
    102111{
    103112        sysarg_t addr;
    104         async_exch_t *exch = async_exchange_begin(dnsr_sess);
     113        async_exch_t *exch = dnsr_exchange_begin();
    105114
    106115        int rc = async_req_0_1(exch, DNSR_GET_SRVADDR, &addr);
    107         async_exchange_end(exch);
     116        dnsr_exchange_end(exch);
    108117
    109118        if (rc != EOK)
     
    116125int dnsr_set_srvaddr(inet_addr_t *srvaddr)
    117126{
    118         async_exch_t *exch = async_exchange_begin(dnsr_sess);
     127        async_exch_t *exch = dnsr_exchange_begin();
    119128
    120129        int rc = async_req_1_0(exch, DNSR_SET_SRVADDR, srvaddr->ipv4);
    121         async_exchange_end(exch);
     130        dnsr_exchange_end(exch);
    122131
    123132        if (rc != EOK)
Note: See TracChangeset for help on using the changeset viewer.