Changeset fff7ef4 in mainline


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).

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/dnsres/dnsres.c

    r287d729 rfff7ef4  
    6565        char *saddr;
    6666
    67         rc = dnsr_init();
    68         if (rc != EOK) {
    69                 printf(NAME ": Failed connecting to DNS resolution service "
    70                     "(%d).\n", rc);
    71                 return 1;
    72         }
    73 
    7467        if (argc != 2) {
    7568                print_syntax();
  • uspace/app/nettest1/nettest1.c

    r287d729 rfff7ef4  
    354354        if (rc != EOK) {
    355355                /* Try interpreting as a host name */
    356                 rc = dnsr_init();
    357                 if (rc != EOK) {
    358                         printf("Failed connecting DNS resolution "
    359                             "service (%d).\n", rc);
    360                         return rc;
    361                 }
    362 
    363356                rc = dnsr_name2host(argv[argc - 1], &hinfo);
    364357                if (rc != EOK) {
  • uspace/app/nettest2/nettest2.c

    r287d729 rfff7ef4  
    300300        if (rc != EOK) {
    301301                /* Try interpreting as a host name */
    302                 rc = dnsr_init();
    303                 if (rc != EOK) {
    304                         printf("Failed connecting DNS resolution "
    305                             "service (%d).\n", rc);
    306                         return rc;
    307                 }
    308 
    309302                rc = dnsr_name2host(argv[argc - 1], &hinfo);
    310303                if (rc != EOK) {
  • uspace/app/nettest3/nettest3.c

    r287d729 rfff7ef4  
    7878                if (rc != EOK) {
    7979                        /* Try interpreting as a host name */
    80                         rc = dnsr_init();
    81                         if (rc != EOK) {
    82                                 printf("Failed connecting DNS resolution "
    83                                     "service (%d).\n", rc);
    84                                 return rc;
    85                         }
    86 
    8780                        rc = dnsr_name2host(argv[1], &hinfo);
    8881                        if (rc != EOK) {
  • uspace/app/nterm/conn.c

    r287d729 rfff7ef4  
    8585        if (rc != EOK) {
    8686                /* Try interpreting as a host name */
    87                 rc = dnsr_init();
    88                 if (rc != EOK) {
    89                         printf("Failed connecting DNS resolution "
    90                             "service (%d).\n", rc);
    91                         goto error;
    92                 }
    93 
    9487                rc = dnsr_name2host(addr_s, &hinfo);
    9588                if (rc != EOK) {
  • uspace/app/ping/ping.c

    r287d729 rfff7ef4  
    245245        if (rc != EOK) {
    246246                /* Try interpreting as a host name */
    247                 rc = dnsr_init();
    248                 if (rc != EOK) {
    249                         printf(NAME ": Failed connecting DNS resolution "
    250                             "service (%d).\n", rc);
    251                         goto error;
    252                 }
    253 
    254247                rc = dnsr_name2host(argv[argi], &hinfo);
    255248                if (rc != EOK) {
  • 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.