Changeset 06fe3b6 in mainline


Ignore:
Timestamp:
2013-05-06T15:58:01Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d531bd6
Parents:
eef14771
Message:

Simple retry mechanism for DNS queries.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/dnsrsrv/transport.c

    reef14771 r06fe3b6  
    5454#define REQ_TIMEOUT (5*1000*1000)
    5555
     56/** Maximum number of retries */
     57#define REQ_RETRY_MAX 3
     58
    5659typedef struct {
    5760        link_t lreq;
     
    184187        struct sockaddr_in addr;
    185188        trans_req_t *treq;
     189        int ntry;
    186190
    187191        req_data = NULL;
     
    196200                goto error;
    197201
    198         rc = sendto(transport_fd, req_data, req_size, 0,
    199             (struct sockaddr *)&addr, sizeof(addr));
    200         if (rc != EOK)
    201                 goto error;
    202 
    203         treq = treq_create(req);
    204         if (treq == NULL) {
    205                 rc = ENOMEM;
    206                 goto error;
    207         }
    208 
    209         fibril_mutex_lock(&treq->done_lock);
    210         while (treq->done != true) {
    211                 rc = fibril_condvar_wait_timeout(&treq->done_cv, &treq->done_lock,
    212                     REQ_TIMEOUT);
    213                 if (rc == ETIMEOUT) {
    214                         fibril_mutex_unlock(&treq->done_lock);
    215                         rc = EIO;
     202        ntry = 0;
     203
     204        while (ntry < REQ_RETRY_MAX) {
     205                rc = sendto(transport_fd, req_data, req_size, 0,
     206                    (struct sockaddr *)&addr, sizeof(addr));
     207                if (rc != EOK)
     208                        goto error;
     209
     210                treq = treq_create(req);
     211                if (treq == NULL) {
     212                        rc = ENOMEM;
    216213                        goto error;
    217214                }
    218         }
    219 
    220         fibril_mutex_unlock(&treq->done_lock);
     215
     216
     217                fibril_mutex_lock(&treq->done_lock);
     218                while (treq->done != true) {
     219                        rc = fibril_condvar_wait_timeout(&treq->done_cv, &treq->done_lock,
     220                            REQ_TIMEOUT);
     221                        if (rc == ETIMEOUT) {
     222                                ++ntry;
     223                                break;
     224                        }
     225                }
     226
     227                fibril_mutex_unlock(&treq->done_lock);
     228
     229                if (rc != ETIMEOUT)
     230                        break;
     231        }
     232
     233        if (ntry >= REQ_RETRY_MAX) {
     234                rc = EIO;
     235                goto error;
     236        }
    221237
    222238        if (treq->status != EOK) {
Note: See TracChangeset for help on using the changeset viewer.